1

I have two lists:

List1=[['Širvintos', 'Alauša ', 'Musninkų g. 4 Širvintos', '2022-04-09'], 
['Vilnius', 'Alauša ', 'Kalvarijų g. 204G Vilnius', '2022-04-09'], 
['Vilnius', 'Alauša ', 'Šiaurės g. 39 Vilnius', '2022-04-09']]

and

List2=[['1.699 ', '1.799 ', '0.00'], 
['1.689 ', '1.789 ', '0.699 '], 
['1.749 ', '1.809 ', '0.679 ']]

I used zip() function and got the outcome:

[[['Širvintos', 'Alauša ', 'Musninkų g. 4 Širvintos', '2022-04-09'], ['1.699 ', '1.799 ', '0.00']], 
[['Vilnius', 'Alauša ', 'Kalvarijų g. 204G Vilnius', '2022-04-09'], ['1.689 ', '1.789 ', '0.699 ']], 
[['Vilnius', 'Alauša ', 'Šiaurės g. 39 Vilnius', '2022-04-09'], ['1.749 ', '1.809 ', '0.679 ']]]

Although two lists were zipped, it is not my desirable outcome. I would like to get something like this:

[['Širvintos', 'Alauša ', 'Musninkų g. 4 Širvintos', '2022-04-09','1.699 ', '1.799 ', '0.00'], 
['Vilnius', 'Alauša ', 'Kalvarijų g. 204G Vilnius', '2022-04-09','1.689 ', '1.789 ', '0.699 '], 
['Vilnius', 'Alauša ', 'Šiaurės g. 39 Vilnius', '2022-04-09','1.749 ', '1.809 ', '0.679 ']]

I want to remove inner square brackets, but I can't find a way to do it. How should I approach this?

  • Well, each list in your result contains two lists, that you want to concatenate together. Do you know how to repeat a process with each element of a list? Do you know how to get the two lists from one of your result lists, and put them together? – Karl Knechtel Apr 08 '22 at 23:41

1 Answers1

2

You can use list comprehension:

[a+b for a,b in zip(List1,List2)]
iacob
  • 20,084
  • 6
  • 92
  • 119