0
Im unable to insert items into a list not sure why
I have take a raw input from user n stored in object L and then I did s=L.split(",") and then I tried to insert items a=s.insert(12,13).then print list (a)
15 Respostas
+ 1
r u sure u r entering elements separated by comma
https://code.sololearn.com/cTjSwe2Q03e2/?ref=app
u can try using above code . it works fine for me
+ 1
input function will return you a string. u have to convert that string into a list based on how u enter the data using split method eg: if u give input as 1,2,3,4,5 then by using split on the string as shown in my code will give u a list [1,2,3,4,5].
+ 1
remember insert is a method of list object and it takes 2 arguments but u have given 3 arguments. and u were getting attribute error as insert method is not there in string object
+ 1
at the index 2 the list is assigned
0
you can paste the error you got so that it will be easy to identify
0
attribute error : 'str object has no attribute 'insert'
0
sandesh help me understand what I'm doing wrong in my code
0
I want to generate a list taking input from user and then do an insert operation on it and print the list
0
so my question is what If I want to insert more than 2 items in a list using insert method?
0
u can check the code that I tagged earlier.
u can use slicing operator to insert multiple elements
0
so what is l[2:2] does??
0
I want my list which I gave via user input and also new list added at the end .Is it possible?
0
I finally got the answer on what I was looking for .I wanted to give some default list to be added along with user input list and this code works perfectly for me.Thank you sandesh for all your help