Python itertools - The key to mastering iteration

Опубликовано: 27 Декабрь 2024
на канале: mCoding
36,198
1.5k

The key to iteration in Python

A key feature of Python is it's incredible support for lazy iteration. Defining and consuming lazy sequences in Python are easy. You can even define an infinite sequence like powers of 2 or prime numbers! To make working with iterables in Python even easier, Python provides some basic building blocks to help you compose iteration primitives in different ways, which is what the itertools module is for. This module comes with 21 different primitives (and many more recipes for how to combine them), which we go over in this video. Will you use them?

― mCoding with James Murphy (https://mcoding.io)

Docs: https://docs.python.org/3/library/ite...
Source code: https://github.com/mCodingLLC/VideosS...

SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
  / mcoding  

Feeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
https://www.paypal.com/donate/?hosted...

Want to donate crypto? Check out the rest of my supported donations on my website!
https://mcoding.io/donate

Top patrons and donors: Laura M, Jameson, Dragos C, Vahnekie, Neel R, Matt R, Johan A, Casey G, Mark M, Mutual Information, Pi

BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord:   / discord  
Github: https://github.com/mCodingLLC/
Reddit:   / mcoding  
Facebook:   / james.mcoding  

CHAPTERS
---------------------------------------------------
0:00 Intro
1:47 An initial warning
2:30 Lookahead motivating multi-accumulate
3:09 ALL 21 ITERTOOLS - itertools.count
3:41 itertools.cycle
4:01 itertools.repeat
4:17 itertools.accumulate
4:58 itertools.batched
5:28 itertools.chain
5:58 itertools.chain.from_iterable
6:18 itertools.compress
6:42 itertools.dropwhile
7:32 itertools.filterfalse
8:18 itertools.groupby
10:08 itertools.islice
11:04 itertools.pairwise
11:47 itertools.starmap
12:43 itertools.takewhile
13:02 itertools.tee
14:22 itertools.zip_longest
14:48 itertools.product
15:43 itertools.permutations
16:15 itertools.combinations
16:55 itertools.combinations_with_replacement
17:22 multi_accumulate example
19:43 Thanks