append at specific index python code example
Example 1: python append in specific position
# --> list.insert(position, element) <--
# List of string
list1 = ['Hi' , 'hello', 'at', 'this', 'there', 'from']
# Add an element at 3rd position in the list
list1.insert(3, 'why')
#-> ['Hi', 'hello', 'at', 'why', 'this', 'there', 'from']
Example 2: append to list at index python
#!/usr/bin/python
aList = [123, 'xyz', 'zara', 'abc']
aList.insert( 3, 2009)
print "Final List : ", aList