简体   繁体   中英

Lining up data in two seperate lists in Python

I would like to combine data from two separate lists into nice table.. I have already tried appending the data into a new list but the the list comes back empty or there is an error code.

My variables are:

x = ['a' , 'd', 'c' , 'b' , 'z']
y = [ '1' , '4', '10', '1' , '22']
z = []

What would be the next step in solving this?

I would like the output for print(z) to be:

a : 1 
d : 4
c : 10
b : 1
z : 22

To print an output like that you say you can use:

for i, j in zip(x, y):
     print(i, ":", j)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM