Issue
That is: each element in a list ends up as the first element in the corresponding list in a list of lists.
Like the following:
List_of_Lists = [[1,2,3],[2,3,4],[4,4,4]]
List1 = [1,2,3]
Resulting:
New_List_of_List = [[1,1,2,3][2,2,3,4],[3,4,4,4]]
I have tried various append and insert methods, but the main problem is that I'm not sure how to mash up individual lists in List_of_Lists and elements in List.
Solution
You can insert the elements at the 0 position
lists = [[1,2,3],[2,3,4],[4,4,4]]
List1 = [1,2,3]
for i in range(len(lists)):
lists[i].insert(0,List1[i])
print(lists)
Output:
[[1, 1, 2, 3], [2, 2, 3, 4], [3, 4, 4, 4]]
Answered By - user15801675 Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.