Python list comprehension 📰

Ғылым және технология

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)
--------------------------------------------------------------

Пікірлер: 52

  • @BroCodez
    @BroCodez3 жыл бұрын

    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
    @ombrenombre74962 жыл бұрын

    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.

  • @jasonunterwegs8991

    @jasonunterwegs8991

    Жыл бұрын

    4 Months later hope you stayed consistend!

  • @ombrenombre7496

    @ombrenombre7496

    Жыл бұрын

    @@jasonunterwegs8991 i did

  • @jasonunterwegs8991

    @jasonunterwegs8991

    Жыл бұрын

    @@ombrenombre7496 glad to hear that! best luck for the next 4 months

  • @Goose____

    @Goose____

    Жыл бұрын

    one year later, hopefully you're still consistent

  • @kapibara2440

    @kapibara2440

    8 ай бұрын

    Same with me!

  • @kszoknyik
    @kszoknyik Жыл бұрын

    Straight to the point. Great content 👌

  • @el_conta
    @el_conta Жыл бұрын

    Genio total!! Thank you very much!

  • @ericafey8958
    @ericafey8958 Жыл бұрын

    Thank you! Very useful

  • @rango099
    @rango0993 жыл бұрын

    another perfect video

  • @shahrirridzuan6924
    @shahrirridzuan6924 Жыл бұрын

    Love it, thanks bro!

  • @expectolimited
    @expectolimited11 күн бұрын

    very nice video

  • @SuperStarEevee
    @SuperStarEevee2 жыл бұрын

    Thank you!

  • @piotrkopcewicz5227
    @piotrkopcewicz5227 Жыл бұрын

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

  • @bekturasanbekov1979
    @bekturasanbekov1979 Жыл бұрын

    thx 4 vid bro ~!

  • @kychemclass5850
    @kychemclass5850 Жыл бұрын

    Excellent tutorial. Tq. Subbed.

  • @feggy585
    @feggy585 Жыл бұрын

    I'll never let this channel die😭

  • @cristiucvladimir7909
    @cristiucvladimir79092 ай бұрын

    thanks for sharing code in comments, very useful

  • @notbastian1887
    @notbastian18872 жыл бұрын

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

  • @kaibeka1598
    @kaibeka1598 Жыл бұрын

    dude much love for you

  • @jhassee
    @jhassee Жыл бұрын

    Thanks for every thing

  • @carterjackson7460
    @carterjackson74603 жыл бұрын

    thanks :)

  • @ryanheapes212
    @ryanheapes2124 ай бұрын

    Excellent content bro!

  • @newperson4889
    @newperson48896 ай бұрын

    Thanks Bro

  • @sivamani2900
    @sivamani29003 ай бұрын

    Beating the algorithm for you :-)

  • @shab2871
    @shab28718 ай бұрын

    i like this

  • @lw9954
    @lw9954 Жыл бұрын

    Ty Bro

  • @jonasziegler2090
    @jonasziegler20905 ай бұрын

    good video

  • @beingzero7541
    @beingzero75412 жыл бұрын

    Wow!

  • @rubenc4696
    @rubenc46962 ай бұрын

    thanks

  • @Mastodonte71
    @Mastodonte71 Жыл бұрын

    🐐

  • @orfredymelobeltran5237
    @orfredymelobeltran52372 жыл бұрын

    thanks.

  • @soulharm5532
    @soulharm55322 жыл бұрын

    Thanks

  • @loveSG999
    @loveSG9993 жыл бұрын

    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

  • @manuelvaal1257
    @manuelvaal12572 жыл бұрын

    excellent

  • @erniewhite7875
    @erniewhite78752 жыл бұрын

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

  • @HussainAli-sb1dv
    @HussainAli-sb1dv8 ай бұрын

    lovw u

  • @Sanjaykumar-bd7ds
    @Sanjaykumar-bd7ds Жыл бұрын

    Who else if learning to code as a beginner?

  • @rowanrodrigues8278
    @rowanrodrigues82786 ай бұрын

    support

  • @MysteryIlusion
    @MysteryIlusion10 ай бұрын

    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

  • @gustavoaponte1814
    @gustavoaponte1814 Жыл бұрын

    meow~!

  • @NoNowwwell
    @NoNowwwell2 ай бұрын

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

  • @josephbarber6140
    @josephbarber61408 ай бұрын

    YALLA

  • @francisakash.x1494
    @francisakash.x14946 ай бұрын

    Just an comment

  • @tsojoshua9459
    @tsojoshua94594 ай бұрын

    bro code can make me come

  • @Leo-io4bq
    @Leo-io4bq Жыл бұрын

    comment

  • @denislavdochev3783
    @denislavdochev3783 Жыл бұрын

    List comprehension is cool, dict comprehension is shi

  • @khanhhoang3840
    @khanhhoang38402 жыл бұрын

    thanks

Келесі