Skip to content

Instantly share code, notes, and snippets.

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