Array ArrayList python equivalent

I just looked up array and arrayList

and found out that an array is fixed length and can't be changed while an arraylist can be changed and is variable in length

my question is:

is array == tuple in python?

and is arraylist == list in python?

and if they aren't what are array and arraylist's python equivalent?

1

2 Answers

ArrayList in java and list in python are both dynamic arrays. They both have O(1) average indexing time and O(1) average adding an element to the end time.

Array in java is not tuple in python. While it is true that you cannot add elements to both data structures. Python tuple does not support assignment, that is you cannot reassign individual elements in a tuple, while you can in java Array.

  • Java's ArrayList is similar to Python's List.
  • Nicer than Array for adding and removing items.
  • Java's Array has fixed length like you mentioned.
  • Not sure what its equivalent in Python would be.
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like