+ 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

29th Aug 2020, 5:04 PM
Sri Dharshini G
Sri Dharshini G - avatar
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!
29th Aug 2020, 5:31 PM
Lothar
Lothar - avatar
+ 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]]
29th Aug 2020, 7:25 PM
Namit Jain
Namit Jain - avatar
+ 3
Well append mehod do works ,not sure what you tried lst=[1,2,3] lst.append([2,3]) print(lst)
29th Aug 2020, 5:16 PM
Abhay
Abhay - avatar
+ 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))
29th Aug 2020, 5:07 PM
Steven M
Steven M - avatar
+ 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
29th Aug 2020, 6:50 PM
Ipang