I have these 2 lists:
char= ['aa', 'bb', 'cc']
and
number= [100, 200, 300]
and I want the following :
result = [ ['aa',100], ['bb',200], ['cc',300] ]
thanks
You can use list comprehension and zip to build the list you desire.
characters = ['aa', 'bb', 'cc']
numbers = [100, 200, 300]
result = [[x, y] for x, y in zip(characters, numbers)]
char= ['aa', 'bb', 'cc']
number= [100, 200, 300]
result=zip(char,number)
list(result)
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.