l.insert(index, obj)
doesn’t actually return anything. It just updates the list.
As ATO said, you can do b = a[:index] + [obj] + a[index:]
.
However, another way is:
a = [1, 2, 4]
b = a[:]
b.insert(2, 3)
More Related Contents:
- What do ellipsis […] mean in a list?
- Python pandas insert list into a cell
- Why is a list comprehension so much faster than appending to a list?
- List on python appending always the same value [duplicate]
- Changing an element in one list changes multiple lists [duplicate]
- Getting only element from a single-element list in Python?
- 2D list has weird behavor when trying to modify a single value [duplicate]
- python filter list of dictionaries based on key value
- In Python, why is list[] automatically global?
- Print LIST of unicode chars without escape characters
- Insert element in Python list after every nth element
- How to add element in Python to the end of list using list.insert?
- Why python’s list slicing doesn’t produce index out of bound error? [duplicate]
- Write and read a list from file
- TypeError: ‘float’ object is not subscriptable
- Unexpected IndexError while removing list items [duplicate]
- How to apply a function to each sublist of a list in python?
- Sort a list with a custom order in Python
- sum each value in a list of tuples
- flatten list of list through list comprehension
- Python and SQLite: insert into table
- TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
- How to sort list of lists according to length of sublists [duplicate]
- Skip elements on a condition based in a list comprehension in python
- Converting string to tuple without splitting characters
- list extend() to index, inserting list elements not only to the end
- Get unique values from a list in python [duplicate]
- Python write to a file returns empty file
- How to concatenate element-wise two lists in Python [duplicate]
- Identify duplicate values in a list in Python