Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

difference between generator and iterator in python

* difference between generator and iterator in python
------------------------------------------
Iterator uses iter() and next() functions 	
Generator uses yield keyword
------------------------------------------
* Iterator
iter_list = iter(['Geeks', 'For', 'Geeks'])
print(next(iter_list))
print(next(iter_list))
print(next(iter_list))

* Generator
def sq_numbers(n):
	for i in range(1, n+1):
		yield i*i


a = sq_numbers(3)

print("The square of numbers 1,2,3 are : ")
print(next(a))
print(next(a))
print(next(a))
Comment

PREVIOUS NEXT
Code Example
Python :: correlation analysis of dataframe python 
Python :: python datetime module 
Python :: get mac address python 
Python :: csv library python convert dict to csv 
Python :: change color of butto in thkinter 
Python :: pandas plot move legend 
Python :: python os abspath 
Python :: python try except raise error 
Python :: df groupby loop 
Python :: python background function 
Python :: pandas front fill 
Python :: count unique values pandas 
Python :: plt.legend( 
Python :: python fillna with mode 
Python :: python nth prime function 
Python :: count frequency of characters in string 
Python :: input command in python shell 
Python :: delete certain characters from a string python 
Python :: random string generate python of 2.7 
Python :: python check if 3 values are equal 
Python :: read csv and store in dictionary python 
Python :: numpy arrauy to df 
Python :: palindrome string python 
Python :: convert list to generator python 
Python :: python remove punctuation 
Python :: read from text file and append in list 
Python :: convert string of list to list python 
Python :: intersect in python list 
Python :: python update multiple dictionary values 
Python :: python string in set 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =