Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging a list with a list of lists

I have a list of lists:

[['John', 'Sergeant '], ['Jack', 'Commander '], ['Jill', 'Captain ']]

How can I merge it with a single list like:

['800','854','453']

So that the end result looks like:

[['John', 'Sergeant', '800'], ['Jack', 'Commander', '854'], ['Jill', 'Captain', '453']]

Initially I tried: zip(list_with_lists,list) but data was obfuscated

like image 296
K DawG Avatar asked Sep 18 '13 12:09

K DawG


1 Answers

a = [['John', 'Sergeant '], ['Jack', 'Commander '], ['Jill', 'Captain ']]
b = ['800', '854', '453']
c = [x+[y] for x,y in zip(a,b)]
print c

Result:

[['John', 'Sergeant ', '800'], ['Jack', 'Commander ', '854'], ['Jill', 'Captain ', '453']]
like image 67
Kevin Avatar answered Oct 12 '22 23:10

Kevin