0

I have 2 lists,

x = ['mandana', 'hamid', 'sina', 'sara', 'soheila', 'ali', 'sarvin']

y = [0, 16.3, 16, 13, 19, 2, 17, 8]

the number of values in 2 lists are always the same how can I merge them together like this into another list? to look something like this :

[('mandana',0), ('hamid', 16.3) , ...]

I have tried some of the solutions in search but non was successful. sorry for stupid question.

update : i already tried zip function, gets me error : 'float' object is not iterable

1 Answers1

0

Python's zip function may be all that you need. https://docs.python.org/3.3/library/functions.html#zip

x = ['mandana', 'hamid', 'sina', 'sara', 'soheila', 'ali', 'sarvin']
y = [0, 16.3, 16, 13, 19, 2, 17, 8]
print(list(zip(x,y)))

This outputs: [('mandana', 0), ('hamid', 16.3), ('sina', 16), ('sara', 13), ('soheila', 19), ('ali', 2), ('sarvin', 17)]