Python Tutorial: Comprehensions - How they work and why you should be using them

  Рет қаралды 519,722

Corey Schafer

Corey Schafer

8 жыл бұрын

Python comprehensions are a very natural and easy way to create lists, dicts, and sets. They are also a great alternative to using maps and filters within python. If you are using maps, filters, or for loops to create your lists, then most likely you could and should be using comprehensions instead.
In this video, we will look at how comprehensions work, why you should be using them, and the benefits they have over the alternatives.
The code from this video can be found at:
github.com/CoreyMSchafer/code...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python

Пікірлер: 495
@just_living_
@just_living_ 5 ай бұрын
8 years after and my man is still better than 90% of other tutorial, cheers man
@zackm7541
@zackm7541 5 жыл бұрын
Corey I hope you always go to bed feeling good about your work and helping out the community. Thanks for your very clear tutorials.
@aayush_7037
@aayush_7037 3 жыл бұрын
Positivity ❤️❤️
@dietrevich
@dietrevich 3 жыл бұрын
I bet he would feel and sleep even better if you supported him.
@SSCrow
@SSCrow 8 жыл бұрын
I have to say that your videos are among the best that I've found on youtube for learning python. You're very well spoken, and your examples are great at illustrating the concepts!
@coreyms
@coreyms 8 жыл бұрын
+Crow Thanks for the kind words. I appreciate it!
@UrsuIrinel
@UrsuIrinel 8 жыл бұрын
+Crow I agree with this. He really knows how to explain things.
@copyrightedchannel4939
@copyrightedchannel4939 3 жыл бұрын
5 years
@lochlanvihaan6892
@lochlanvihaan6892 2 жыл бұрын
I guess im asking the wrong place but does anyone know of a tool to log back into an Instagram account?? I was dumb forgot my login password. I love any help you can give me
@buzz.b
@buzz.b Жыл бұрын
This is an exceptional tutorial on list comprehensions. The use of writing out what we want in normal language, seeing it implemented in a loop, and then how it translates to a list comprehension makes it very clear and intuitive. I never quite got comfortable with them when I originally learnt this, but your method of teaching it allowed me to understand the concept. Many thanks.
@jeffreystockdale8292
@jeffreystockdale8292 7 жыл бұрын
1st time seen this explained, I agree, your lack of "ummms, uhs, hold-ons, etc." are very pleasing to the ear, great instructor. Thanks.
@mateuszpolanski3162
@mateuszpolanski3162 3 жыл бұрын
Corey, I never leave any comments under YT videos but man, your tutorials are just something else. Cannot THANK YOU enough for being such an amazing teacher. I love everything about them: the way you explain concepts, carefully go through examples over and over again...and you just sound like a cool guy! Thanks for everything Corey, truly appreciate you are here for us.
@ajith1804
@ajith1804 4 жыл бұрын
To be frank,this is the best video for learning about list comprehension on KZfaq!
@kerwinso
@kerwinso 4 жыл бұрын
Corey, you have really helped me to make the leap from beginner to intermediate Python programmer. I'd heard of list comprehensions before, but never dictionary comprehensions. Once again, many many thanks!
@sandeepanbhattacharyya828
@sandeepanbhattacharyya828 3 жыл бұрын
yes so true. I came to learn list comprehensions now going back with even more comprehensions :)))
@24junar
@24junar 7 жыл бұрын
This is the best python tutorials I've ever seen so far. Clear, very detailed, even the examples and text editor you've use is perfect. thanks, looking forward for more advance python techniques in the future. Once again.. thank you so much
@RandomShowerThoughts
@RandomShowerThoughts 5 жыл бұрын
the amount of material I have learned from this channel is literally amazing!
@Ryebanana
@Ryebanana 4 жыл бұрын
Glad I found your channel. I am working my way through Automate the Boring Stuff with Python and stopping after every chapter and watching your videos has helped so much in understanding the topics in greater detail.
@kedwards127
@kedwards127 5 жыл бұрын
You just saved me on my homework assignment. I looked at several resources online and asked three different people and your video is the only thing that made the light bulb in my head turn on (in learning dictionary comprehensions)!! Thank you.
@amandaahringer7466
@amandaahringer7466 2 жыл бұрын
Just spent a couple hours reading articles, watching videos, and practicing nested comprehensions. The whole time I was thinking "wow if Corey had a video on this it would have been so much faster and easier to understand!" Your channel is awesome :)
@saradeeee
@saradeeee 7 жыл бұрын
YES! thank you so so much! All other tutorials kind of just mention this casually thinking that we understand what is going on, but we cant really know what's happening until someone actually explains it! You are an amazing teacher
@uiato
@uiato 4 жыл бұрын
CONCISE and ELOQUENT are the words for you. First content youtube channel that I don't have to speed up the videos. Thanks!!!
@MegaJohn144
@MegaJohn144 5 жыл бұрын
I just started learning Python and decided to rewrite a program in Python that I first wrote in C++. I wanted to use a lot of these Python features to eliminate all those those for-loops. So far, my Python program is turning out to be a lot more complex than I thought it would be. (I think I'm over-thinking the problem.) I'm hoping I can use list comprehension to eliminate a lot of that coding and fully utilize the power of Python. I happened to find your video, and I know it is really going to help me. I was also looking for a way to code, debug, and run .py files. You are doing things in Sublime Text that I didn't know you could do. I'm looking forward to watching the video again and following along, as well as watching more of your videos.
@jialiangpan7258
@jialiangpan7258 Жыл бұрын
This is by far the best tutorials on list comprehension I’ve ever got online. Thank you so much!
@rotrose7531
@rotrose7531 5 жыл бұрын
Your python series conquer the whole youtube, the explanation is concise and to the point. I especially enjoy those real word examples, Hope you will make a series to feature more and more real world examples. Thank you.
@novicetech1
@novicetech1 6 жыл бұрын
Wow! Now I finally understand list comprehensions. Thanks Corey. Another great tutorial.
@AundreL
@AundreL 4 жыл бұрын
4 years later still the best tutorial available thank you so much, sir.
@RC-bl2pm
@RC-bl2pm 6 жыл бұрын
Boy you're a good teacher! Great explanation followed by meaningful demonstration. Clear.Punchy. Keep going I'll keep watching.
@spizeck
@spizeck 8 жыл бұрын
Brilliantly done. You were very well prepared and it showed. Bravo sir.
@sahilsharma-hj4gq
@sahilsharma-hj4gq 5 жыл бұрын
oh mannnnnn....... simply AWESOME.. You teach way better than most of the python tutors. Your detailed explainations are dope.
@serhiy2020
@serhiy2020 8 жыл бұрын
This is probably my favorite feature in Python. Thanks for these videos, you're a great teacher!
@bartuslongus
@bartuslongus 2 жыл бұрын
Thank yo so much Corey for all your tutorial videos! They are exactly the format I need to learn this language and coming back when I struggle doing it myself just to see that you already mentioned it. Coming from a Java backgound I really enjoy being able to do such great things so easily and having so clear instructions how to do it (right). Combining it with a Raspberry Pico and Unicorn hat makes it so much more enjoyable and motivates me to try out even more cool stuff!
@darrenandveronica
@darrenandveronica 8 жыл бұрын
Succinct yet comprehensive, and beautifully explained. I am really getting a lot clearer about python through your videos - thank you.
@djcoolio8096
@djcoolio8096 5 жыл бұрын
The best explanation ever! You're making our lives so much easier! Thanks!
@database_tips_tricks
@database_tips_tricks 2 жыл бұрын
I hope you never take down these videos , so convenient to always be able to come back to them again when not understanding at first and then real life situation makes one have to u understand and then these videos are so helpful THANK YOU best python learning channel I ever used
@ezraanna1
@ezraanna1 4 жыл бұрын
I think you are very good at Python and the way you present things; clear & to the point. You are among the best out there. God bless you!
@mandeepubhi4744
@mandeepubhi4744 5 жыл бұрын
An elegant approach of illustration, Beautiful!!!
@kwrifles
@kwrifles 2 жыл бұрын
best video ive found so far on the subject, you break it down the information in easily digestible sizes. appreciate it and subbed
@AlexKashie
@AlexKashie 10 ай бұрын
Thank you Corey, content made 7 years ago and still fresh.
@iiit2tech
@iiit2tech 4 жыл бұрын
Must say your videos are best in class and I have learnt so much from them. Your explanations are very clear and makes even tricky concepts easy to grasp.
@tongliu1076
@tongliu1076 5 жыл бұрын
I watched every topic video before the topic my class is going to reach. It makes my class so easy.
@aisolutions834
@aisolutions834 2 жыл бұрын
Wow, a concise video teaching elegantly creating lists, dictionaries, sets, and generators!
@ROC4Life96
@ROC4Life96 5 жыл бұрын
This wasn't what i was looking for, BUT i am very glad i stumbled upon this video! Thank you!
@shazkingdom1702
@shazkingdom1702 5 жыл бұрын
I suddenly remember my best Algebra 👨‍🏫 because of you! - Thanks Corey, I wonder where you are right now, want to shake hands with you and meet you!, You are a great teacher. 👨‍🏫
@JAREMAIALOOK
@JAREMAIALOOK 5 жыл бұрын
I am very grateful that you make these videos, keep up the great work!
@jaroffdaniel5242
@jaroffdaniel5242 2 жыл бұрын
I would say your videos are so much useful. I am just getting started with python but these comprehensive videos are rapidly making to go to intermediate level of code manipulation and understanding... THANK YOU SO MUCH!!!!!!!
@aposaheed4543
@aposaheed4543 2 жыл бұрын
You are the best tutor for me. I understand ur style than anyone. Thanks
@soumyazyx
@soumyazyx 4 жыл бұрын
Thank you Corey for your time and effort. Keep spreading the knowledge
@peterchen5710
@peterchen5710 4 жыл бұрын
Finally see an ad in this tutorial video! Chosen not to skip the ad so Corey gets the pay from KZfaq! This is the least I can do to express my gratitude for the great teacher!
@riyan5259
@riyan5259 4 жыл бұрын
I'm so mad at the viewers for not subscribing.. Mate you DESERVE a million subscribers.
@whimsicalkins5585
@whimsicalkins5585 2 жыл бұрын
Thanks for your detailed explanation. I appreciate the efforts put by you to explain the difference between naive approach and list comprehension.
@HappyAnimals3D
@HappyAnimals3D 5 жыл бұрын
This was very informative. Your examples helped a great deal.
@jehushaphat
@jehushaphat 2 жыл бұрын
This was the most comprehensive video I've seen on comprehension.
@davidtodd9918
@davidtodd9918 4 жыл бұрын
Thanks. I had not heard of set comprehension or generator creation using parens, and I appreciated the excellent refresher on other topics!
@deepgsingh
@deepgsingh 5 жыл бұрын
Awesome, I have watched all of your python videos and they are great stuff , Thank you
@trevordontstalkme1303
@trevordontstalkme1303 2 жыл бұрын
Thank you. Even though i didn't come for list comprehension this solved my lack of knowledge with lists in python! Definitely will look more into your channel once i need to seek more knowledge.
@ProbuddhaNag
@ProbuddhaNag 7 жыл бұрын
I am learning Python and your videos have been more than helpful. Thank you very much!
@chigglywiggly
@chigglywiggly 4 жыл бұрын
Best series of videos on Python on the internet.
@tunkyi7162
@tunkyi7162 5 жыл бұрын
Thank you bro. Your lectures are GOLD!
@battlemode
@battlemode 7 жыл бұрын
Really good tutorial, very clearly and concisely explained. Thank you!
@simondolapo1567
@simondolapo1567 2 жыл бұрын
All I can say is amazing contents never die...They still live for decades to come
@Abcsciencemusic
@Abcsciencemusic 3 жыл бұрын
I was trying to learn that for over a year but never got that the exact format or remember it. But you saved me. SO WELL EXPLAINED .merry christmas
@DeanG621
@DeanG621 3 жыл бұрын
I like your vids, they are well explained. It helped me to get two things straight and use list comprehensions: The first n in for n in nums is the same as my_list.append(n) The one-liner has the same built as a for loop. First for n in nums and then the if.
@lamarts100
@lamarts100 8 жыл бұрын
Great job! This is way better than the for loops. Crystal clear explanation...
@difegam3
@difegam3 3 жыл бұрын
Unfortunately it is not possible give you more than 1 like. You are the best man! Thanks Corey.!
@ArunKumar-qy6fm
@ArunKumar-qy6fm 5 жыл бұрын
Explained wonderfully. Thank you.
@priyankkharat7407
@priyankkharat7407 5 жыл бұрын
Amazing tutorial! Very Helpful
@zzspenz7492
@zzspenz7492 8 жыл бұрын
...great way to bring into context lambda and functional - very clear/informative, excellent!!
@Gameplays4u2
@Gameplays4u2 5 жыл бұрын
OMG you made these concepts to simple it took me forever to understand generators till I found your video.
@lokeshbhatt4u
@lokeshbhatt4u 7 жыл бұрын
Great, fast paced contents with nice illustrations !
@firstfiverugby
@firstfiverugby 3 жыл бұрын
Preparing for my code interview tomorrow. Thank you for this video. Will most likely be brushing up more often now so I will be back :)
@TheJAM_Sr
@TheJAM_Sr 2 жыл бұрын
Dude you are a rockstar! Thank you for making this easy to follow tutorial!!
@anuradhapani1918
@anuradhapani1918 8 жыл бұрын
very nicely explained! thanks
@leithhawkins2165
@leithhawkins2165 7 жыл бұрын
Awesome Tuts. Well thought through but clear and concise ! well done
@pmt4297
@pmt4297 2 жыл бұрын
BIG LIKE for this video! Your videos are great but this one answered some of my main questions about coding in Python. Thanks a million.
@joselima9398
@joselima9398 7 жыл бұрын
finally, you have glued this together in my head. thanks!
@theegreatestever2420
@theegreatestever2420 2 жыл бұрын
ABSOLUTELY AMAZING EXPLANATIONS!
@GuilhermeMendesG
@GuilhermeMendesG 3 жыл бұрын
Briliant explanation, man. Thank you very much!
@nedimcanulusoy
@nedimcanulusoy 3 жыл бұрын
It was an amazing and helpful video Corey! Thanks a lot!
@bgable7707
@bgable7707 3 жыл бұрын
Well done, KISS, great examples !!!
@lennyadams8275
@lennyadams8275 7 жыл бұрын
Fantastic video! Thank you for sharing your knowledge with us, Corey! :-)
@user-yk9rr5ir7v
@user-yk9rr5ir7v Жыл бұрын
Great video! The concept of list and dictionary comprehensions was very well and clearly explained. I understand it much better now. I just want to add that the generator expression at the end can all just be written in one line I believe: print(list(n*n for n in nums)) though that would only print it as a list rather than line by line.
@emperornugz89
@emperornugz89 Жыл бұрын
Using these videos to fill in some of the gaps I've had while reading "Automate the Boring Stuff". Been making cheat sheets to code along with off your videos!
@akira_asahi
@akira_asahi Жыл бұрын
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
@peternguyen6266
@peternguyen6266 3 жыл бұрын
Wow, your video are the best out there. It's so easy to understand.
@ppant
@ppant 5 жыл бұрын
You are a great teacher. Keep it up! Thanks
@anotter_one
@anotter_one 3 жыл бұрын
Man, you're the real MVP. Thanks a bunch.
@geekyprogrammer4831
@geekyprogrammer4831 6 жыл бұрын
You definitely deserve more views!
@enockaddey
@enockaddey 7 жыл бұрын
Thanks so much! Great examples.Very helpful!
@prasadp8265
@prasadp8265 4 жыл бұрын
Best Python tutorials in youtube!
@boxcubestudios
@boxcubestudios 4 жыл бұрын
Fantastic teaching!
@pavelpavlov8143
@pavelpavlov8143 6 жыл бұрын
Great stuff.Thanks Corey!!!
@VMSaloudi
@VMSaloudi 8 жыл бұрын
A person could be a good programmer but good programmer != good teacher. You are the best python teacher on KZfaq. Thanks for making our lives easier by putting the hard work in making those videos and explaining the concepts in simple and understandable form. Also, whenever you have time, please consider making video on decorators.
@mariaaraujo3042
@mariaaraujo3042 6 жыл бұрын
well, he still is a good teacher!
@nemplayer1776
@nemplayer1776 5 жыл бұрын
@Nico Braun He just told him he's the worst python programer on KZfaq lol. Could also be interpreted as good programmer != good teacher, but you can't say best programmer != best teacher, as otherwise programmer != teacher would be correct.
@pmons1337
@pmons1337 6 жыл бұрын
this is beautiful can't wait to get into your tutorial
@snpsforyomom
@snpsforyomom 7 жыл бұрын
awesome video! I didn't know about sets and generator compressions. will be trying them out. thanks!
@cralx2k
@cralx2k 3 жыл бұрын
Amazing teacher... THANK YOU
@TheKaushal8686
@TheKaushal8686 5 жыл бұрын
best python videos on youtube..
@w.schobel1514
@w.schobel1514 8 жыл бұрын
your videos are brilliant! glad i found your channel
@bulldawg4498
@bulldawg4498 5 жыл бұрын
Excellent presentation ...
@nazaserh
@nazaserh 3 жыл бұрын
As always, a fantastic lesson. 👏
@Noah-qj9fn
@Noah-qj9fn 3 жыл бұрын
This is extremely useful. Thanks!
@vladi21k
@vladi21k 4 жыл бұрын
Thank you for this great tutorial!
@maziarghorbani
@maziarghorbani 7 жыл бұрын
You are a talented tutor. Thanks
@arthuralexandersson
@arthuralexandersson 2 жыл бұрын
Very useful even after 6 years, thank you!
@lovejaexi707
@lovejaexi707 5 жыл бұрын
thank you!you are amazing at teaching! love you~
@PacifiqueNzitonda
@PacifiqueNzitonda 6 жыл бұрын
I'm beginner in Python and I learn it for Rigging task in Maya. Thank you so much!!!
@aminzaiwardak6750
@aminzaiwardak6750 3 жыл бұрын
thanks a lot, you explained very well.
Python Tutorial: Sorting Lists, Tuples, and Objects
12:07
Corey Schafer
Рет қаралды 266 М.
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,8 МЛН
How many pencils can hold me up?
00:40
A4
Рет қаралды 19 МЛН
10 Python Comprehensions You SHOULD Be Using
21:35
Tech With Tim
Рет қаралды 108 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 352 М.
THIS is Why List Comprehension is SO Efficient!
5:25
b001
Рет қаралды 168 М.
List Comprehension - BEST Python feature !!! Fast and Efficient
14:51
Python Simplified
Рет қаралды 185 М.
PLEASE Use These 5 Python Decorators
20:12
Tech With Tim
Рет қаралды 92 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1 МЛН
Python lists, sets, and tuples explained 🍍
15:06
Bro Code
Рет қаралды 226 М.
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,8 МЛН