Zion
Zion

Reputation: 1610

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?

Upvotes: 11

Views: 44319

Answers (2)

Akavall
Akavall

Reputation: 86266

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.

Upvotes: 20

David
David

Reputation: 69

  • 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.

Upvotes: 0

Related Questions