Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Generators

>>> mygenerator = (x*x for x in range(3))
>>> for i in mygenerator:
...    print(i)
0
1
4
Comment

# generators

# generators
gen_1= (x*x for x in [1,2,3])   # [1, 4, 9]
gen_2 = (x+x for x in gen_1)  # [2, 8, 18]
for i in gen_2:
   print(i)

# 2
# 8
# 18
 
for i in gen_1:
   print(i)


# Nothing is displayed
# With generators, instead of storing data in the variable gen_1 (and therefore in memory), you are going to generate them on the spot (e.g. only when you need them).
# Careful: Generating data on the spot does not allow to read them several times. And if you try to do so, no error will be raised to warn you.
Comment

PREVIOUS NEXT
Code Example
Python :: fetch the appropriate version based on chrome python 
Python :: loop through dataframe and assign values based on previous row 
Python :: django admin link column display links 
Python :: rtdpy ncstr 
Python :: add constant to all values of columns in dataframe python 
Python :: import 
Python :: scipy random seed 
Python :: sort vs sorted python 
Python :: const in python 3 
Python :: intersect and count in sql 
Python :: find mising number in O(n) 
Python :: what is certifi module in python 
Python :: unpad zeros from string python 
Python :: islink(node1 node2) is used for 
Python :: pylint no name in module opencv 
Python :: call for a last number in series python 
Python :: paramhans ramchandra das 
Python :: which is best between c and python for making application 
Python :: phow to install python modules in no internet in sercer 
Python :: python turn seconds into zulu time 
Python :: fibonacci sequence algorithm python 
Python :: KivyMD video recording 
Python :: matplotlib FiveThirtyEight creating a signature 
Python :: list all subdirectories up to a level 
Python :: df.loc jupyter 
Python :: mechanize python XE #25 
Python :: converting string key to int py 
Python :: pandas meerge but keep certain columns 
Python :: python laplace expansion 
Python :: Doubleclick .py Prep 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =