A Deep Dive Into Iterators and Itertools in Python

preview_player
Показать описание
Python has some amazing built-in functions and modules for working with iterators. In this video, I take a deep dive into iterators and itertools in Python and how to use iterators for your own projects!

🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

🔖 Chapters:
0:00 Intro
1:34 What is an Iterator?
2:16 Examples
4:24 Iterator vs Iterable
10:58 Build your own iterators
12:38 Itertools package
20:12 Outro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

This is the kind of videos we all need!
Please more of deep diving into python standard library, still a lot of modules that are not used or misused by a growing number of people.

aflous
Автор

bravo, Arjan! Waiting for a video on functools

arturkabitcher
Автор

I too really like the deeper dive. Being able to use stock standard modules efficiently is a key component of coding.
Thank you!

thisoldproperty
Автор

My favorite use is in paginated synchronous API calls. I can mask the pagination process from the consumer while iterating across records, allow the consumer to stop before reaching the final page, and in doing so potentially reduce API calls.

It also makes it easy to implement retries and backoffs while maintaining state.

ClifBratcher
Автор

I also love the deep dives. Please keep them comming!

MedievalChips
Автор

Hi Arjan, thanks for the lesson. I never used itertools before, now i now it's capability. thanks for the examples

RonaldPostelmans
Автор

This is amazing!! Love the python Deep dives.

takudzwamakusha
Автор

Great idea! I'm looking forward to this new series!

pazuzil
Автор

What a way to break the ice! Thank you 😎 Unless I missed existing content, may I kindly suggest an episode featuring argument/keyword argument unpacking?

pepecopter
Автор

Yet another great video, Love these deep dives, thanks

TimLauridsen
Автор

I usually also use more_itertools, really cool for windowing logic

rasputunga
Автор

Also, make tutorials on the internal workings of core python. Maybe like memory management, unusual behaviors of some methods.

santoshbhattarai
Автор

My most used function fom itertools is groupby, to get groups of items wiith the same "identifier". Ofter used in combination with sorted. For example you have a list of tuples and whant to group by all tuples with the same first item.

maxmuster
Автор

Using itertools and iterators for a while.
`more_itertools` is a very useful package built on top of itertools, and in fact is recommended in the itertools docs.

Shivnaren
Автор

These deep dives are awesome! Thank you, Arjan!

onage
Автор

Nice video!
I'm not using itertools that much, but it's nice to see that a bunch of those functions (like starmap) are also available on the multiprocessing.Pool object (also in the stdlib). There starmap works exactly the same, except that each function call is done in a subprocess. That's basically Python's way to do parallel execution without bothering with the GIL. I used that recently to write a large number (80k-ish) of YAML files :)

Автор

This is a great idea - I used to subscribe to Python Module of the Week and this is a brilliant replacement!

dankprole
Автор

Nice, I didn't know about starmap. I feel like you should be able to deconstruct tuple arguments in lambdas directly, but this is much better than indexing.

Another one I needed sometimes is islice, which skips elements at the beginning and ends early based on two index-like numbers.

okdoomer
Автор

Thank you for this video! I am still waiting for a series about architecture in video game! Unfortunatelly, there was only video about plugins

grzegorzryznar
Автор

The pairwise function can be very useful when you need an element and its successor in a iterable. It returns the pairs made of consecutive values. For instance : pairwise([1, 3, 5]) = (1, 3), (3, 5)
I use it when I need to compute the mean of two consecutive values.

MBB