0

I have two list of list data and I am trying to concatenate the two list of data in python. I used regular expression in extracting data from my desired file and collected the required fields by creating a list. For example if the list 1 and list 2 has data:

lst1 = [['60', '27702', '1938470', '13935', '18513', '8'], ['60', '32424', '1933740', '16103', '15082', '11'], ['60', '20080', '1946092', '9335', '14970', '2']]

lst2 = [['2', '1'], ['11', '1'], ['12', '1']]

I will like to see the data like below:

lst3 = [[60, 27702, 1938470, 13935, 18513, 8, 2, 1],

[60, 32424, 1933740, 16103, 15082, 11, 11, 1],

[60, 20080, 1946092, 9335, 14970, 2, 12, 1]]

How do I receive lst3 ??

  • 8,4,1 should probably be 8,2,1, can you confirm / [edit] your question – Jean-François Fabre May 08 '17 at 17:08
  • Possible duplicate of [How to append list to second list (concatenate lists)](http://stackoverflow.com/questions/1720421/how-to-append-list-to-second-list-concatenate-lists) – Preston Martin May 08 '17 at 17:40
  • Possible duplicate of [Merge Lists in Python](http://stackoverflow.com/questions/35881399/merge-lists-in-python) – SiHa May 09 '17 at 07:32

1 Answers1

3

Just interleave both sublists using zip, and convert the joined list members to integers in a list comprehension:

lst3 = [[int(x) for x in l1+l2] for l1,l2 in zip(lst1,lst2)]

result

[[60, 27702, 1938470, 13935, 18513, 8, 2, 1],
[60, 32424, 1933740, 16103, 15082, 11, 11, 1],
[60, 20080, 1946092, 9335, 14970, 2, 12, 1]]
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219