Calls to itertools.imap()
in Python 2 or map()
in Python 3 can be replaced by equivalent generator expressions:
sum(1 for dummy in it)
This also uses a lazy generator, so it avoids materializing a full list of all iterator elements in memory.
More Related Contents:
- What’s the shortest way to count the number of items in a generator/iterator?
- What exactly are iterator, iterable, and iteration?
- Difference between Python’s Generators and Iterators
- How to print a generator expression?
- What are iterator, iterable, and iteration?
- Can iterators be reset in Python?
- If range() is a generator in Python 3.3, why can I not call next() on a range?
- Is there an expression for an infinite iterator?
- When is not a good time to use python generators?
- Length of generator output [duplicate]
- Why does next raise a ‘StopIteration’, but ‘for’ do a normal return?
- Understanding generators in Python
- Lazy Method for Reading Big File in Python?
- How can I iterate over files in a given directory?
- Get the first item from an iterable that matches a condition
- How do I know if a generator is empty from the start?
- Resetting generator object in Python
- How to len(generator()) [duplicate]
- Python generator that groups another iterable into groups of N
- How to convert an iterable to a stream?
- How to get the n next values of a generator in a list (python)
- How can I generate all possible IPs from a list of ip ranges in Python?
- Python: using a recursive algorithm as a generator
- Return in generator together with yield
- What does the “yield” keyword do in Python?
- How to clone a Python generator object?
- Generator functions equivalent in Java
- Pass multiple parameters to concurrent.futures.Executor.map?
- Do python’s variable length arguments (*args) expand a generator at function call time?
- Star * operator on left vs right side of an assignment statement