Based on this older thread, it looks like the cost of list functions in Python is:
- Random access: O(1)
- Insertion/deletion to front: O(n)
- Insertion/deletion to back: O(1)
Can anyone confirm whether this is still true in Python 2.6/3.x?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Take a look here. It’s a PEP for a different kind of list. The version specified is 2.6/3.0.
Append (insertion to back) is
O(1), while insertion (everywhere else) isO(n). So yes, it looks like this is still true.