Advertisement
here2share

# insert_pitfall.py

Nov 6th, 2022
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.17 KB | None | 0 0
  1. # insert_pitfall.py
  2.  
  3. # pitfall
  4. a = [1,2,3,4]
  5. a.insert(-1,5)
  6. print (a)
  7. # [1, 2, 3, 5, 4]
  8.  
  9. # solution
  10. a = [1,2,3,4]
  11. a.insert(len(a),5)
  12. print (a)
  13. # [1, 2, 3, 4, 5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement