List Comprehension Basics with Python (Python Tutorial #12)

///List Comprehension Basics with Python (Python Tutorial #12)

List Comprehension Basics with Python (Python Tutorial #12)

FavoriteLoadingAdd to favorites

List comprehension basics in Python – let’s go!

This entire series in a playlist:

Also, find me on Instagram:
And Twitter:
And Facebook:

source

By |2019-07-30T21:33:40+00:00July 30th, 2019|Python Video Tutorials|31 Comments

31 Comments

  1. Neeshen Gounden July 30, 2019 at 9:33 pm - Reply

    YK, please make more videos. Yours videos are extremely good and helpful. Kind regards, NG

  2. Harsh Mirdhwal July 30, 2019 at 9:33 pm - Reply

    Very very grateful to you csdojo , Thank you very very much!!!!!

  3. Az-Zahraa July 30, 2019 at 9:33 pm - Reply

    how do i expand one of the element in the list? =<

  4. Marcos Bispo July 30, 2019 at 9:33 pm - Reply

    sqr2 = [i ** 2 for i in range(-6, 0)]

  5. Felidrummer1 July 30, 2019 at 9:33 pm - Reply

    e3 = []

    for x in range(-6, 0):

    e3.append(x ** 2)

    print(e3)

  6. Yogesh Gupta July 30, 2019 at 9:33 pm - Reply

    list1=[]
    for i in range(6,0):
    x=i**2
    list1.append(x)
    i=i-1
    print(list1)

    why doesnt this work?

  7. Gökhan Parıltı July 30, 2019 at 9:33 pm - Reply

    # a = [36, 25, 16, 9, 4, 1]

    a = []

    for x in range(1,7):

    a.append(x ** 2)

    a.reverse()

    print(a)

  8. Luis Solano July 30, 2019 at 9:33 pm - Reply

    Please more videos! you are awesome bruh! 🙂

  9. Ahmad Abzakh July 30, 2019 at 9:33 pm - Reply

    You can also use:

    list = []
    for i in range(1,7):
    list.append((i-7) **2 )
    print(list)

    or:

    list = [((i-7) ** 2) for i in range(1,7)]
    print(list)

  10. Clark Lee July 30, 2019 at 9:33 pm - Reply

    f1 = [x ** 2 for x in range(-6, 0)]
    print("f1 is ", f1)
    #range function increases 1 each time by default.

  11. Quif July 30, 2019 at 9:33 pm - Reply

    list1 = []
    for x in range(1, 7):
    list1.append(x ** 2)
    list1.reverse()
    print(list1)

  12. 阿偉 July 30, 2019 at 9:33 pm - Reply

    #creat a list = [36,25,16,9,4,1]

    Solution 1:
    a = []

    for i in range(1,7):

    i = i-7

    i = i**2

    a.append(i)

    print(a)

    Solution 2:
    a = [(i-7)**2 for i in range(1,7)]

    print(a)

    For people who don't know range(6,0,-1)beforehand, I think these two options are also acceptable.

  13. s vaseekaran July 30, 2019 at 9:33 pm - Reply

    Will you pleases upload the next next videos as soon as possible

  14. TheLegendaryDragon 99 July 30, 2019 at 9:33 pm - Reply

    a = []

    for i in range(1, 7):

    a.append(i ** 2)

    a.reverse()

    print(a)

  15. E&C EXPERTS July 30, 2019 at 9:33 pm - Reply

    f = [x**2 for c in range (1, 7)]
    f.reverse()
    print(f)

  16. kalyan baidya July 30, 2019 at 9:33 pm - Reply

    We can also do it by creating range(-6, 0).and then do it in the exact same way as before..

  17. Hitsugaya July 30, 2019 at 9:33 pm - Reply

    test = []
    for x in range (1, 7):
    test.append(x ** 2)

    print(test[::-1])

    it works,tho 😀

  18. Vthechamp Gaming July 30, 2019 at 9:33 pm - Reply

    There is another way to solve the problem at 4:40. Just do e2.reverse()

  19. Alpha Outruler July 30, 2019 at 9:33 pm - Reply

    can someone tell me why I'm getting an error in line 2 here:
    e1 = []

    for x in range(1, 7):

    e1.append(x ** 2)

    print(e1)
    it says TypeError: 'tuple' object is not callable

  20. Sir Bimbo July 30, 2019 at 9:33 pm - Reply

    It can be like this too.

    a = [ i**2 for i in range(1, 7)]
    print(a[::-1])

  21. Hani Abdallah July 30, 2019 at 9:33 pm - Reply

    Nice Tutorial , but we can use also list.reverse() much easier 🙂

  22. Kabir Nayeem July 30, 2019 at 9:33 pm - Reply

    Thank you. You helped me a lot.

  23. jawad mansoor July 30, 2019 at 9:33 pm - Reply

    Either python is indescribably easy or you are incredibly good teacher. I mean, I have no background of programming.

  24. sum guy July 30, 2019 at 9:33 pm - Reply

    New to coding/Python. I really appreciate these videos, your examples are typically better than other teachers because while they are still trivial, they add enough context to make the code make sense.

    Looking at this, I guess we can recalc the problem you posed on the earlier tutorial (sum of 1->100 where %5 or %3 are 0) using list comprehension with the CONDITIONAL element? Is there any disadvantage to this approach:

    sum([x for x in range(1,101) if (x%3==0 or x%5==0)])

  25. mark doors July 30, 2019 at 9:33 pm - Reply

    Hello CS Dojo. I want to know if you have any complete real live training course in Python. I mean in a group basis. please let me know. my email is markdoors123456@gmail.com

  26. mark doors July 30, 2019 at 9:33 pm - Reply

    Hello CS Dojo. Thank you for the video. Can we use the following syntax for the reverse range?
    g = [x**2 for x in range (-6, 0)]
    print(g)
    the Answer is also (36, 25, 16, 9, 4, 1).

  27. michael-james bassford July 30, 2019 at 9:33 pm - Reply

    Your videos are well made and have helped me(a beginner) get a first understanding of Python.Thanks mate and keep up the good work!

  28. All of it - About all July 30, 2019 at 9:33 pm - Reply

    b=[x**2 for x in range(1,7)]

    b.reverse()

    print(b)

  29. Merik Ostensen July 30, 2019 at 9:33 pm - Reply

    I am getting this error
    —————————————————————————

    AttributeError Traceback (most recent call last)

    <ipython-input-3-fc98df6d876d> in <module>

    1 b = []

    —-> 2 b.append = (10)

    3 b.append = (20)

    4 print(b)

    AttributeError: 'list' object attribute 'append' is read-only

    how do i fix it?

  30. MD.Mehedi hasan July 30, 2019 at 9:33 pm - Reply

    can you please make a video on java programming

  31. McKenzie NM July 30, 2019 at 9:33 pm - Reply

    My solution was different:
    e2.reverse()
    print(e2)

    Solution:
    [36, 25, 16, 9, 4, 1]
    I feel like I took the easy way out…

Leave A Comment

*