How to add elements at different positions?
Title
Question
By using append function we can add element at last position but how can we add elements at different positions rather than last position
Python-3.4.3 Getting-started-with-Lists 07-08 min 10-20 sec
Answers:
You can use the list.insert(position, element) method
For example
l = [1, 2, 4]
If I want to add an element after 2 then the insert command is
l.insert(2, 3)
new list becomes
l = [1, 2, 3, 4]
Login to add comment