List Insert in Python
Level 246 keystrokes
This inserts an element at a specific position in a list. The insert() method takes an index and a value.
Python code
# Create a list where 2 is missing between 1 and 31nums = [1, 3, 4]# insert(1, 2) puts the value 2 at index 1# The elements from index 1 onward (3 and 4) shift one place to the right2nums.insert(1, 2)# Prints [1, 2, 3, 4]3print(nums)Output
[1, 2, 3, 4]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 3(× 2)× 2.× 1[× 1]× 1=× 1