Lazy Iterators v List Comprehensions in Python

preview_player
Показать описание
A lazy iterator in Python is often implemented using a generator expression, denoted by (...).

A generator expression is similar to a list comprehension but produces values lazily, one at a time, as they are requested.

If you want a fast VPS server with Python installed check out :
---------------------------------------------------------------------------------------------------

Thumbs up yeah? (cos Algos..)

#iterators #tutorial #pythonprogrammingtutorial
Рекомендации по теме
Комментарии
Автор

Just defining this iterator is of course blazingly fast but evaluating is not faster.

The lazy iterator is just an EXPRESSION that gets evaluated when you run list(lazy_iterator). This will take about as much time as running the list comprehension because then you are actually calculating and storing these values.

In other words list(lazy_iterator) is actually just a list comprehension in disguise.

The lazy iterator is indeed actually useful if you don‘t need to store all values of the expression you are iterating over.

juliandeal