Python list comprehension 📰

Поділитися
Вставка
  • Опубліковано 5 сер 2024
  • python list comprehension tutorial example explained
    #python #list #comprehension
    list comprehension = a way to create a new list with less syntax
    can mimic certain lambda functions, easier to read
    list = [expression for item in iterable]
    list = [expression for item in iterable if conditional]
    list = [expression if/else for item in iterable]
    --------------------------------------------------------------
    squares = [] # create an empty list
    for i in range(1,11): # create a for loop
    squares.append(i * i) # define what each loop iteration should do
    print(squares)
    create a list AND defines what each loop iteration should do
    squares = [i * i for i in range(1,11)]
    print(squares)
    --------------------------------------------------------------
  • Наука та технологія

КОМЕНТАРІ • 53

  • @BroCodez
    @BroCodez  3 роки тому +30

    tldr
    # list comprehension = a way to create a new list with less syntax
    # can mimic certain lambda functions, easier to read
    # list = [expression for item in iterable]
    # list = [expression for item in iterable if conditional]
    # list = [expression if/else for item in iterable]
    # --------------------------------------------------------------
    squares = [] # create an empty list
    for i in range(1,11): # create a for loop
    squares.append(i * i) # define what each loop iteration should do
    print(squares)
    # create a list AND defines what each loop iteration should do
    squares = [i * i for i in range(1,11)]
    print(squares)
    # --------------------------------------------------------------
    students = [100,90,80,70,60,50,40,30,0]
    passed_students = list(filter(lambda x: x >= 60, students))
    passed_students = [i for i in students if i >= 60]
    # passed_students = [i if i >= 60 else "FAILED" for i in students]
    print(passed_students)
    # --------------------------------------------------------------

  • @ombrenombre7496
    @ombrenombre7496 2 роки тому +62

    I like how you have around 83k in the first video of the series and on this you have only around 4k, I won't give up like others Im going to stay here till I learn this complete.

  • @kszoknyik
    @kszoknyik Рік тому

    Straight to the point. Great content 👌

  • @el_conta
    @el_conta Рік тому

    Genio total!! Thank you very much!

  • @ericafey8958
    @ericafey8958 Рік тому

    Thank you! Very useful

  • @expectolimited
    @expectolimited 23 дні тому

    very nice video

  • @rango099
    @rango099 3 роки тому

    another perfect video

  • @shahrirridzuan6924
    @shahrirridzuan6924 Рік тому

    Love it, thanks bro!

  • @kychemclass5850
    @kychemclass5850 Рік тому

    Excellent tutorial. Tq. Subbed.

  • @feggy585
    @feggy585 Рік тому +1

    I'll never let this channel die😭

  • @piotrkopcewicz5227
    @piotrkopcewicz5227 Рік тому

    I liked I commented I subscribed months ago, I hope i keep this channel running :)

  • @bekturasanbekov1979
    @bekturasanbekov1979 Рік тому

    thx 4 vid bro ~!

  • @kaibeka1598
    @kaibeka1598 Рік тому

    dude much love for you

  • @SuperStarEevee
    @SuperStarEevee 2 роки тому

    Thank you!

  • @notbastian1887
    @notbastian1887 2 роки тому +3

    Question: Can you actually put an elif statement into a list comprehension?
    Your videos help me a lot btw, thank you so much!

  • @ryanheapes212
    @ryanheapes212 5 місяців тому

    Excellent content bro!

  • @jhassee
    @jhassee Рік тому

    Thanks for every thing

  • @cristiucvladimir7909
    @cristiucvladimir7909 3 місяці тому

    thanks for sharing code in comments, very useful

  • @carterjackson7460
    @carterjackson7460 3 роки тому

    thanks :)

  • @jonasziegler2090
    @jonasziegler2090 5 місяців тому

    good video

  • @shab2871
    @shab2871 8 місяців тому

    i like this

  • @sivamani2900
    @sivamani2900 4 місяці тому

    Beating the algorithm for you :-)

  • @newperson4889
    @newperson4889 7 місяців тому

    Thanks Bro

  • @beingzero7541
    @beingzero7541 2 роки тому

    Wow!

  • @lw9954
    @lw9954 Рік тому

    Ty Bro

  • @rubenc4696
    @rubenc4696 3 місяці тому

    thanks

  • @orfredymelobeltran5237
    @orfredymelobeltran5237 2 роки тому

    thanks.

  • @soulharm5532
    @soulharm5532 2 роки тому

    Thanks

  • @manuelvaal1257
    @manuelvaal1257 2 роки тому

    excellent

  • @Mastodonte71
    @Mastodonte71 Рік тому

    🐐

  • @erniewhite7875
    @erniewhite7875 2 роки тому

    Great job, but how about one that has compound comprehensions?

  • @HussainAli-sb1dv
    @HussainAli-sb1dv 8 місяців тому

    lovw u

  • @loveSG999
    @loveSG999 3 роки тому +4

    Takes a bit of getting used to, but worth trying

    • @jasonunterwegs8991
      @jasonunterwegs8991 Рік тому

      @every thing yo just asking how are you doing in python after 3 months? hope you do good m8

  • @MysteryIlusion
    @MysteryIlusion 11 місяців тому

    Dear bro, I love your vids but is there any chance that you can add like 5 exercises at the end of your video for every topic you do, maybe a link to github rep will do. thaanks

  • @rowanrodrigues8278
    @rowanrodrigues8278 6 місяців тому

    support

  • @Sanjaykumar-bd7ds
    @Sanjaykumar-bd7ds Рік тому +1

    Who else if learning to code as a beginner?

  • @gustavoaponte1814
    @gustavoaponte1814 Рік тому

    meow~!

  • @NoNowwwell
    @NoNowwwell 3 місяці тому

    List comprehension feels circular and self referential to me.
    i for i in i for i. Like...WHAT.

  • @josephbarber6140
    @josephbarber6140 9 місяців тому

    YALLA

  • @francisakash.x1494
    @francisakash.x1494 6 місяців тому

    Just an comment

  • @tsojoshua9459
    @tsojoshua9459 4 місяці тому

    bro code can make me come

  • @Leo-io4bq
    @Leo-io4bq Рік тому

    comment

  • @denislavdochev3783
    @denislavdochev3783 Рік тому

    List comprehension is cool, dict comprehension is shi

  • @khanhhoang3840
    @khanhhoang3840 2 роки тому

    thanks