Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 5, 2020 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/5524f0dcbbb97637bd5c91849d8d2951 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/5524f0dcbbb97637bd5c91849d8d2951 to your computer and use it in GitHub Desktop.
import itertools
#times argument is not mentioned. It will result in infinite loop.
l1=itertools.repeat(2)
print (next(l1))#Output:2
print (next(l1))#Output:2
#string is used as an argument.times argument is mentioned as 10.It will repeat the string 10 times.
l2=itertools.repeat("hello",times=10)
for i in l2:
print (i,end=" ")#Output:hello hello hello hello hello hello hello hello hello hello
print (" ")
#list is used as argument
l3=itertools.repeat([1,2,3],times=3)
for i in l3:
print (i,end=" ")#Output:[1, 2, 3] [1, 2, 3] [1, 2, 3]
print (" ")
#tuple is used as an argument
l4=itertools.repeat(('red','blue'),times=3)
for i in l4:
print (i,end=" ")#Output:('red', 'blue') ('red', 'blue') ('red', 'blue')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment