Answers for "python get item from generator"

1

python generators

# Size of generators is a huge advantage compared to list
import sys

n= 80000

# List
a=[n**2 for n in range(n)]

# Generator
# Be aware of the syntax to create generators, lika a list comprehension but with round brakets
b=(n**2 for n in range(n))

print(f"List: {sys.getsizeof(a)} bitsnGenerator: {sys.getsizeof(b)} bits")
Posted by: Guest on October-08-2020

Code answers related to "python get item from generator"

Python Answers by Framework

Browse Popular Code Answers by Language