Python Tutorial: Itertools Module - Iterator Functions for Efficient Looping

Поділитися
Вставка
  • Опубліковано 11 гру 2024

КОМЕНТАРІ • 238

  • @wolfisraging
    @wolfisraging 6 років тому +237

    U r seriously a world class teacher
    Thanks man

  • @programmer4833
    @programmer4833 4 роки тому +5

    Incredible video ! I love is when he says : 'If you don't know smth' and then explains it, as I am used to getting a link to another video or no explanation at all. I learned so many things !

  • @VikasGuptacherie
    @VikasGuptacherie 6 років тому +7

    One thing that I like about this channel is the right pace in which video moves...

  • @ibekwevictor1158
    @ibekwevictor1158 2 роки тому +4

    The best youtube teacher you can ever think of... Thanks for the Tutorial sir...

  • @festivalofcolorsholinyc9031
    @festivalofcolorsholinyc9031 6 років тому +55

    tee is like a T is a pipe (like with fluid in it). It's an analogy with unix piping.
    On *nix you can:
    Command1 | tee file.txt | command2
    And it will pipe the output of command1 to tee which will write it to the file 'file.txt' and in turn pipe it to command2.

  • @medi7573
    @medi7573 6 років тому +37

    Best python on youtube ,and even away better than paid courses ,thanks man.

  • @Lu_Ca
    @Lu_Ca 6 років тому +20

    best itertools tutorial, should be in the official page imo

    • @rautermann
      @rautermann 5 років тому +1

      Yes. I'm glad I found that explanation for the groupby function. Official documentation on this is unreadable.

  • @karanagarwal282
    @karanagarwal282 4 роки тому +23

    The first thing to do after getting a job: Become a Patreon for this channel

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

    Hands down the best education video on python itertools

  • @JassimBjj
    @JassimBjj 6 років тому +9

    Hey, Corey, I'm a python beginner and I've started watching your python tutorials a few days ago. And I just wanted to tell you that you're a great teacher. I wish that I had found out about you 3 months ago when I started. I'm a Treehouse student, I like it there but they don't really explain as well as you do. So thank you, Corey, I appreciate your great work.

    • @coreyms
      @coreyms  6 років тому

      Thanks!

    • @Ocelot911
      @Ocelot911 6 років тому

      yeah bro once you do the treehouse beginner just quit it - it's not worth it

  • @josephomondi629
    @josephomondi629 6 місяців тому +1

    man, I dont' even know how to thank you enough....this is such a good tutorial.

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

    Thanks for the helpful video. English is a foreign language for me, but you speak and explain very clearly.

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

    I'm learning and using courses and tutorials almost all my life. And I can say with certainty - Corey is brilliant at teaching!

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

    This is the best description/explanation of itertools that I have seen.
    Thank you so much for this video.

  • @DrDeuteron
    @DrDeuteron Рік тому +4

    Improvements:
    5:07 zip(itertools.count(), data) ---> enumerate(data)
    38:57 get_state = operator.itemgetter('state')

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

      the difference between enumerate() and itertools.count() is that you can set a step value for count

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

      the point of the video was to demonstrate itertools. There was no indication in the video that the examples were the best and only way to do things...

  • @marcd4144
    @marcd4144 6 років тому +2

    This is probably the best itertools instructional on video... What a useful module! Very good job!

  • @lowyieldbondfunds
    @lowyieldbondfunds 6 років тому +3

    One of the most concise lessons about itertools in Python. Thanks Corey!

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

    This Guy is the best Python Teacher ever. I learnt Python from his Videos. I hope you r fine since I don't see any latest videos.

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

    I've seen python videos of many tutors on UA-cam but Corey and Navin (from the Telusko channel) are my favorites. Both are amazing teachers ❤❤

  • @MinkoTerziyski
    @MinkoTerziyski 6 років тому +1

    I don't know, why you sharing all this knowledge, but I am extremely, extremely thankful!

  • @Adi-xy8iu
    @Adi-xy8iu 4 роки тому +2

    You cleared all my doubts in itertools.
    Thank You

  • @jfr9964
    @jfr9964 5 років тому +2

    Hey, just want to say that I self-learned Python and your videos were a great help to me when I first started out. Now, I just remembered the channel and came over to see whether it still continues, and your teaching quality has somehow yet improved! Many thanks, and please keep doing this. I learned a lot in this video even though I already knew itertools. Thanks again, and cheers to many more lessons!

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

    ur way is simple but greatly effective and the examples just make it look soo easy and help to remember it longer

  • @shikhargupta7552
    @shikhargupta7552 4 роки тому +1

    Dude, simply excellent 🙏🙏

  • @johannes-euquerofalaralema4374
    @johannes-euquerofalaralema4374 3 роки тому

    Awesome! I have learned so much on your channel! Thank you!! You have a gift that not many people have!

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

    Apart from being the gold standard python videos, your videos also serve as the video documentation!!

  • @Worldnme
    @Worldnme 4 роки тому

    You are actually really good in teaching also the way you talk is so understandable for me and it's simple so keep up

  • @muthuhari8875
    @muthuhari8875 6 років тому +105

    Hi Corey please do videos about async in python

  • @AM-cw9wg
    @AM-cw9wg 3 роки тому

    I am really grateful for these tutorials. Thank u.

  • @vinamraagrawal8672
    @vinamraagrawal8672 4 роки тому +1

    Nobody in this planet could have explained better than you. Keep up your good work. Just a small request, if you could break your python playlist in small categories it would make related videos easy to find.

  • @DoFlamingo_1P
    @DoFlamingo_1P 5 років тому

    i've watched this two times now, its just nicely explained and crafted . Thoroughly enjoyed it .

  • @UncleLoren
    @UncleLoren 4 роки тому +1

    This is an excellent video. Thank you, Corey! Sure, there are alternative (but more verbose) ways of carrying out many of these operations using "base python" But in the same way that comprehensions allow one to get away with writing less loops, it's the expressiveness of itertools that has me sold. As a pandas user, it was also interesting to pick up some new ideas about how 'groupby'/grouper objects can be used.

  • @darkbanditEX
    @darkbanditEX 4 роки тому

    This video had great content and every second was worth watching.
    Thanks you for the video Corey.

  • @lalu225
    @lalu225 6 років тому +5

    Fantastic, very well explained and I learned something new. Thank you!

  • @IdanRefaeli3
    @IdanRefaeli3 5 років тому +2

    Such a high standard video! Appreciated!

  • @davidpuliti
    @davidpuliti 6 років тому +1

    Corey, I believe the tee function comes from Unix and the idea of pipes. If you want to split the flow, you put a “T” pipe in the middle which would output 2 streams. Think plumbing. Thanks for the video.

    • @CharlesDibsdale
      @CharlesDibsdale 6 років тому

      In the UK there is a term where you can ‘tee off’ from a pipe when you add a new pipe branch. Nothing to do with golfing

  • @johnathaningle8812
    @johnathaningle8812 6 років тому +1

    Thank you so much for your all your work. You are the best teacher ever :)

  • @kai-luenliang6565
    @kai-luenliang6565 4 роки тому

    Wow, thank you...that was the best explanation the itertools ever!

  • @cbaxtermusic
    @cbaxtermusic 6 років тому +4

    just when you think you got the hang of this stuff you explode my mind lol great video man!!!!!!

  • @opiyosebastian
    @opiyosebastian 6 років тому +1

    Always the best....Good job Corey!

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

    Great presentation of some heavy concepts. Thanks!

  • @kevinduigou3212
    @kevinduigou3212 6 років тому +1

    Thank you from France!

  • @CharlesDibsdale
    @CharlesDibsdale 6 років тому +1

    Just brilliant. Thanks Corey

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

    this language is incredible

  • @colonelkob
    @colonelkob 6 років тому +1

    Awesome tutorial, your so thorough in your videos, thanks Man 👊

  • @chris-vecchio
    @chris-vecchio 6 років тому +1

    Thanks for the great tutorial and practical examples for each function.

  • @Puppysacks
    @Puppysacks 6 років тому +1

    Hi, I’m new to your channel and I’d rlly like to say thank you for making these videos! It has rlly given me the encouragement I needed to continue to learn. The way you walk us through the process, to where it’s easy enough for a beginner like me, I’m grateful.

  • @vasudev16180
    @vasudev16180 6 років тому +9

    Wow corey ...Love you from India

  • @netuse4956
    @netuse4956 4 роки тому

    comprehensive ,excellent explanation ,, loved it

  • @pylvr8021
    @pylvr8021 6 років тому +1

    thanks corey , can t wait your next video

  • @stanislavkerimov
    @stanislavkerimov 6 років тому +1

    Thank you very much! You are describing so clear and understandable!

  • @BasicallySteve23
    @BasicallySteve23 6 років тому +1

    Great video! These are some seriously useful tools.

  • @iamtimmo
    @iamtimmo 6 років тому +9

    “Tee” almost certainly comes from the Unix/Linux command of the same name. The name plays on the Unix concept of pipes as I/O plumbing and represents a tee plumbing fitting[1] that divides a single incoming flow into two or more output flows (in plumbing, it can do the opposite, too, and combine multiples into one). In the Unix case, tee takes input on STDIN and outputs it to both STDOUT and the file (or files) given as its arguments.
    [1] en.m.wikipedia.org/wiki/Piping_and_plumbing_fitting#Tee

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

    All I can say is that I love you. I'm NOT crying.

  • @imransuleiman2684
    @imransuleiman2684 6 років тому +1

    Thanks man. we thank you for sharing this invaluable knowledge with us

  • @khachatur2000
    @khachatur2000 6 років тому +2

    Thank you a lot for tutorial and timing. It is very useful.

  • @ashishm8850
    @ashishm8850 6 років тому +2

    With Corey, perfection is the norm. Thanks!

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

    Golden videos, thank you very much!

  • @emilksenzovski885
    @emilksenzovski885 5 років тому +12

    thank you for your videos, i learn from them a lot, also i have a question about using zip with count,
    at 4:30 you wrote:
    daily_data = zip(itertools.count(), data)
    why instead not to use enumerate? :
    daily_data = enumerate(data)
    the benefit in functionality with the count is that you can make step
    what is the difference in performance, memory usage, etc?

    • @mohmmadqudah2331
      @mohmmadqudah2331 4 роки тому

      if you use enumerate it well not be asigned inside a list but using itertools well make that happen
      enumerate = 0 "good"
      1 "bad"
      itertools = [(0,"good"),(1,"bad")]

    • @emilksenzovski885
      @emilksenzovski885 4 роки тому +1

      He uses itertools.count inside of zip, both zip and enumerate give you iterator of tuples.
      I didn't understand your point

    • @Boringpenguin
      @Boringpenguin 4 роки тому

      itertools.count() is more versatile
      Note that at 6:15, a "step" argument can be passed into itertools.count(), which is not possible for enumerate().
      So, for enumerate(), we can only control the starting index, the step size is fixed to 1 and we cannot pass in any argument to change it.
      While for itertools.count(), we can change both the starting index and the step size by passing in the corresponding arguments.

    • @tysontakayushi8394
      @tysontakayushi8394 4 роки тому

      @@emilksenzovski885 because he presented the itertools functions.

  • @karanh874
    @karanh874 4 роки тому

    You are amazing Corey

  • @GodsNode
    @GodsNode 6 років тому +1

    Great video as always, buddy.

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

    Thank you very much for this video and for all of your work!

  • @neerajkulkarni6506
    @neerajkulkarni6506 3 роки тому +1

    I love iterators!

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

    Excellent video! Thanks for sharing

  • @nawendusingh2858
    @nawendusingh2858 6 років тому +1

    200k congrats !!!!!

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

    Thank you very much. From VietNam

  • @sociologie4507
    @sociologie4507 6 років тому +1

    good job Corey!

  • @mrpuppeteer2834
    @mrpuppeteer2834 3 роки тому +1

    Thank you very much for covering this topic. I deeply appreciate it. Everything was covered in detail..
    Was thinking about the group by() function lately. It makes no sense that the items have got to be listed in order for the grouping to work..
    Wish the they could add more functionality to the groupby

  • @sosa_3400
    @sosa_3400 Рік тому +2

    5:20 *enumerate() has left the chat.*

  • @slickwillie3376
    @slickwillie3376 5 років тому +5

    The 'tee' fn may refer to a 'tee' fitting in plumbing, which forks off into two directions.

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

    Lots of Love, Saved my sleep.

  • @ferenclippai1059
    @ferenclippai1059 4 роки тому

    Youre a great teacher. Keep the content coming! :)

  • @SheilaHer
    @SheilaHer 6 років тому +2

    COREY! YOU'RE AWESOME!!! I'M SUBSCRIBED!!!

  • @500magnum4
    @500magnum4 11 місяців тому +1

    takewhile and dropwhile might be useful for dealing with alarms on reading machine sensor data.

  • @adithyabhat4770
    @adithyabhat4770 5 років тому +1

    Great tutoial

  • @damodargoud6263
    @damodargoud6263 4 роки тому +2

    thanks corey .

  • @aryan7069_
    @aryan7069_ 4 роки тому

    perfectly explained !!! Thanks a lot sir

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

    Thanks a lot Corey !

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

    T as a letter can be seen from bottom to top. The bottom is the input iterator and the top has two output iterator copies. Hence itertools.tee()

  • @neerajbansal2613
    @neerajbansal2613 5 років тому +1

    Thanks , very helpful.

  • @greob
    @greob 6 років тому +63

    Nice and clear demonstration, as always. Thanks!
    44:41 yep, sounds like it comes from the Linux tee program. It comes from the fact that it splits the output into two, like a T shaped pipe.

    • @coreyms
      @coreyms  6 років тому +10

      Oh interesting. Thanks!

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

      @@coreyms it actually predates linux, coming from quite early unix, as do most linux commands and internal shell commands. ps This is another truly excellent leaning video.

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

    I really like the way you simplified everything. I have been struggling to understand itertools module for a long time. The truth is, I am new to python and am looking for a mentor. Can you be my mentor. Looking forward to your reply.

  • @1b0o0
    @1b0o0 6 років тому +2

    Hi Corey!
    Are you planning on tackling data science stuff like Matplotlib, Pandas, Numpy, Keras, etc?
    I find your vids of tremendous value. Keep'em coming!

    • @abail7010
      @abail7010 5 років тому

      For a very good Keras Tutorial including the math behind machine learning (only if you're interested in, its not necessary) , have a look at the deeplizard playlists! It helped me a lot!

  • @frenamakenson9844
    @frenamakenson9844 8 місяців тому +1

    thank you for sharing man, very usefull

  • @manometer7854
    @manometer7854 5 років тому +1

    Amazing teach video! Wow!

  • @pythonlearning1932
    @pythonlearning1932 4 роки тому

    wondeful corey, BTW, tee command in unix is used to route the output bothe to stdin and to a file(like logging) at the same time

  • @bowenwang
    @bowenwang 6 років тому +1

    Love from China

  • @purna3595
    @purna3595 6 років тому +1

    Hi Corey Schafer,you are simply awesome ,Can you please do lectures on searching and sorting algorithms using python

  • @donsurlylyte
    @donsurlylyte 4 роки тому

    really useful tools, TY

  • @insanecbrotha
    @insanecbrotha 4 роки тому

    @groupby example:
    for key, group in person_group:
    print(f"{key}: {sum(1 for i in group)}")
    would be way to avoid the list cast (eg if you would like to stick with lazy iterators).

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

    one suggestion I have is to teach the module with some more in depth problem or even project examples. I've gone through the actual docs line by line in the past but the only time I really remember the "feeling" of how to use these tools is when I applied them in actually creating solution to a problem or even a code challenges. I don't think we learn to code by memorization but through implementation and by example.

  • @mankan3765
    @mankan3765 6 років тому +1

    Ur videos are awsome

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

    it's great ... Thanks man 🍏

  • @meosh930
    @meosh930 5 років тому

    The tee command is named after the T-splitter in plumbing, which splits water into two directions and is shaped like an uppercase T.
    Suppose you wish to get the number of files in your directory and also store them in a new file.
    Intuitively, you may come up with something as this, ls -l > listOfFiles.txt | wc -l
    But there's a problem. All the output of ls -l is redirected to creating listOfFiles.txt file. So, the first part works really well. And there's for there's nothing 'left' to redirect to the 'wc -l' command, since, redirection to a file doesn't really return anything.
    To achieve what we wanted to achieve, we pass the output of ls -l to 'tee'. Tee does two things, writes to the file whose name is mentioned after the tee command and also sends it to command that comes after.
    ls -l | tee listOfFiles.txt | wc -l
    This would display the number of lines that ls - l outputs, while at the same time writing the list of files to the file 'listOfFiles.txt'.
    Once you get what it's trying to achieve it becomes easier to apply. Just remember when you send something to tee, it would split it two ways, 1) to the file, 2) to the next command in place.

  • @actechforlife
    @actechforlife 6 років тому +5

    hands down, these are the most in-depth python tutorial materials I've ever gone through. Thanks, buddy.
    subscribe++
    like++
    recommend_to_friends = "ABSOLUTELY YES"

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

    Thanks, Awesome!!

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

    One remark on the tee function... It does allow one to have "copies" of iterators but it's an illusion. The copies are in fact *buffered* iterators, so be careful with memory because the second "copy" will be using the items that were pushed into memory when you were exhausting the first "copy."

  • @yem.t.3930
    @yem.t.3930 3 роки тому

    Thank you so much!

  • @dennisasamoah2213
    @dennisasamoah2213 5 років тому +1

    great content

  • @desmondade
    @desmondade 6 років тому

    Thanks you so much Corey Schafer
    please can you do a video in Threading, and sockects? Thanks so much for the good works u have been doing