+ 1
How to insert a list into another list?.
I have to insert one list into the another but insert and append will not work
5 Réponses
+ 8
Sri Dharshini G , please show us your code that does not give the desired result. Also provide a sample of how your result should look like. Thanks!
+ 5
x = [1,2,3,4]
x.append([1,2,3])
x.insert(2,[1,2,3])
print(x)
Output: [1,2,[1,2,3],3,4,[1,2,3]]
+ 3
Well append mehod do works ,not sure what you tried
lst=[1,2,3]
lst.append([2,3])
print(lst)
+ 2
Which language? I will assume Python... Are you looking to do something like this?
lst=[1,2]
print(lst)
lst2=[2,3,4]
print(lst2)
lst+=lst2
print(sorted(lst))
+ 2
Sri Dharshini G
Please avoid writing codes into the thread tags, put relevant words in there instead. For example, a specific language and/or subject e.g. -> Python list