Learn Python list comprehensions 📃

Sdílet
Vložit
  • čas přidán 1. 06. 2024
  • List comprehension = A concise way to create lists in Python
    Compact and easier to read than traditional loops
    [expression for value in iterable if condition]
    doubles = [x * 2 for x in range(1, 11)]
    triples = [y * 3 for y in range(1, 11)]
    squares = [z * z for z in range(1, 11)]
    fruits = ["apple", "orange", "banana", "coconut"]
    uppercase_words = [fruit.upper() for fruit in fruits]
    fruit_chars = [fruit[0] for fruit in fruits]

Komentáře • 21

  • @BroCodez
    @BroCodez  Před 29 dny +3

    # List comprehension = A concise way to create lists in Python
    # Compact and easier to read than traditional loops
    # [expression for value in iterable if condition]
    doubles = [x * 2 for x in range(1, 11)]
    triples = [y * 3 for y in range(1, 11)]
    squares = [z * z for z in range(1, 11)]
    fruits = ["apple", "orange", "banana", "coconut"]
    uppercase_words = [fruit.upper() for fruit in fruits]
    fruit_chars = [fruit[0] for fruit in fruits]
    numbers = [1, -2, 3, -4, 5, -6, 8, -7]
    positive_numbers = [x for x in numbers if x >= 0]
    negative_numbers = [x for x in numbers if x < 0]
    even_numbers = [x for x in numbers if x % 2 == 0]
    odd_numbers = [x for x in numbers if x % 2 == 1]
    grades = [85, 42, 79, 90, 56, 61, 30]
    passing_grades = [grade for grade in grades if grade >= 60]

  • @ranjeetprasad4586
    @ranjeetprasad4586 Před 29 dny +8

    I am from India what a melodious voice u have

  • @gianghoang4594
    @gianghoang4594 Před 29 dny +1

    Love your vids

  • @technicalswag3925
    @technicalswag3925 Před 26 dny +1

    Sir please continue and complete the react course

  • @SabonaMarara
    @SabonaMarara Před 29 dny +2

    true teacher

  • @JohnBrillianton
    @JohnBrillianton Před 19 dny

    Thanks Bro

  • @Ctrl-Z-Renders
    @Ctrl-Z-Renders Před 29 dny

    You are both a good teacher and a good person,
    i think that because you got 6000 usd for a good cause!

  • @Veryprogamer123
    @Veryprogamer123 Před 29 dny +1

    tutoiral on ALL of oop please

  • @AhmadH345
    @AhmadH345 Před 29 dny +1

    W video as always

  • @Norro_o
    @Norro_o Před 24 dny

    pls make a video about explaining grid in css🙏🙏

  • @xzex2609
    @xzex2609 Před 29 dny

    I wonder if bro making these videos, recently . cause after making React tutorials he wants to take some time off. if it is we are all happy that you back. and we hope to learn Next.js from you.

  • @user-yp3jb6me5p
    @user-yp3jb6me5p Před 29 dny

    Sit back relax and enjoy

  • @aj_the_cutiepatootie
    @aj_the_cutiepatootie Před 29 dny

    Bro Code teaching me more in 10 minutes than my IT teacher teaching me the same material in 2 weeks😭

  • @user-oe1yq9pm3d
    @user-oe1yq9pm3d Před 25 dny

    can u pls mmake a video about numpy arrays

  • @alinegomes9084
    @alinegomes9084 Před 28 dny

    loved

  • @exyoris4079
    @exyoris4079 Před 29 dny +1

    why is he redoing these python videos? he already had made a video on list comprehensions

  • @wndos
    @wndos Před 29 dny +1

    150 missed calls from coding schools

  • @NinjaDude_YT
    @NinjaDude_YT Před 29 dny

    When I try to run the script at 4:54, I keep getting this AttributeError and exit code 1. What happened?

    • @xzex2609
      @xzex2609 Před 29 dny

      you may confuse fruit (singular) with fruits (plural) if you get error , also you need to use () after fruit.upper()
      upper = [ fruit.upper() for fruit in fruits]

  • @Veryprogamer123
    @Veryprogamer123 Před 29 dny +1

    third!