Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 5, 2020 04:56
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/ad7fdaf372739ac8ef522ff144996c84 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/ad7fdaf372739ac8ef522ff144996c84 to your computer and use it in GitHub Desktop.
import itertools
#itertools.repeat() used in zip()
l1=[5,15,25]
l2=zip(itertools.repeat(2),l1)
#It will return zip object which is an iterable instance of zip class
print (l2)#Output:<zip object at 0x032794E8>
#we can convert zip object to list.
print (list(l2))#Output:[(2, 5), (2, 15), (2, 25)]
# We can access zip object by using for loop.This is more efficient way to access large sequences.It won't be memory intensive.
l3=zip(itertools.repeat("hello"),l1)
for i in l3:
print (i)
'''
Output:
('hello', 5)
('hello', 15)
('hello', 25)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment