Reputation: 1982
I have lists like..
l1=[1,2,3]
l2=[7,3,4]
i need output like
l3=[[1,2,3],[7,3,4]]
Upvotes: 0
Views: 1270
Reputation: 41
For:
l1 = [1, 2, 3]
and
l2 = [7, 3, 4]
and
l3 = []
you can:
l3.append(l1)
and
l3.append(l2)
l3 = [l1, l2]
l3 = [l1] + [l2]
Upvotes: 2
Reputation: 1057
In this case you can use
l3=[l1,l2]
If you want to insert l2 into l1 at some particular index you can make use of .insert function of lists
list.insert(index,object)
l1.insert(2,l2)
Hope it helps.
Upvotes: 1
Reputation: 82440
You can simply do something like this:
>>> l1=[1,2,3]
>>> l2=[7,3,4]
>>> [l1, l2]
[[1, 2, 3], [7, 3, 4]]
Upvotes: 4
Reputation: 5252
Based on your update not requiring pandas, you can simply do this:
l1=[1,2,3]
l2=[7,3,4]
l3 = [l1] + [l2]
Output:
[[1, 2, 3], [7, 3, 4]]
Upvotes: 1