Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to add items in list in python at specific position

# Python3 program for Insertion in a list  
# before any element using insert() method 
  
list1 = [ 1, 2, 3, 4, 5, 6 ]
  
# Element to be inserted 
element = 13 
  
# Element to be inserted before 3
beforeElement = 3 
  
# Find index
index = list1.index(beforeElement) 
  
# Insert element at beforeElement 
list1.insert(index, element) 
print(list1)
Comment

PREVIOUS NEXT
Code Example
Python :: python file save 
Python :: python catch any exception 
Python :: df.loc a list of index 
Python :: How Generate random number in python 
Python :: current page django 
Python :: to divide or not to divide solution 
Python :: how to replace a string in python 
Python :: what is python -u 
Python :: sklearn labelbinarizer in pipeline 
Python :: list in python 
Python :: values django 
Python :: dtype function with example 
Python :: python save plot 
Python :: logical operators in python 
Python :: extract address from text python 
Python :: what is the weather today 
Python :: how to write manual querry in drf 
Python :: append to list in dict python 
Python :: pandas disply options 
Python :: tkinter how to update optionmenu contents 
Python :: dict ;get a key of a value 
Python :: Reading Custom Delimited 
Python :: limpar idle python 
Python :: find an element using id in requests-html library in python 
Python :: django add to cart 
Python :: import in python 
Python :: 3d plot 
Python :: matplotlib ax.annotate color of the arrow 
Python :: how to access app.config globally in flask app 
Python :: Adding Route In Django 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =