PYTHON ZIP LISTS :

What will you do when you have two lists, where in you need to merge both list by there index to list of tuple

How to achieve this ?    [1, 2, 3]  merge ['one', 'two', 'three']  = [(1, 'one'), (2, 'two'), (3, 'three')]

ANS : Iterate over for loop and generate a list of tuples by iterating over lists which are needed to be merged based on index.

Scrap answer.....

Use zip() build-in function to achieve

CODE:


 x = [1, 2, 3]
 y = ["one", "two", "three"]
 zipped = zip(x, y)
 print "zipped = ",zipped
 x_new, y_new = zip(*zipped)

 print "x_new = ",x_new
 print "y_new = ",y_new


OUTPUT:


zipped =  [(1, 'one'), (2, 'two'), (3, 'three')]
x_new =  (1, 2, 3)
y_new =  ('one', 'two', 'three')


What else you need :)  ?