The zip function takes two or more sequences and creates a new sequence of tuples where each tuple contains one element from each list.
let's see an example :
>>> a = [1, 2, 3, 4, 5]
>>> b = ['a', 'b', 'c', 'd', 'e']
now we will use zip( ) function, like this
>>> zip(a, b)
<zip at 0x5fdb7d8>
let's see an example :
>>> a = [1, 2, 3, 4, 5]
>>> b = ['a', 'b', 'c', 'd', 'e']
now we will use zip( ) function, like this
>>> zip(a, b)
<zip at 0x5fdb7d8>
now we will see the list of resultant list:
>>> list(zip(a, b))
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')]
Like this we can use the zip() method.
No comments:
Post a Comment