When it comes to Python’s "list", is it wrong to call it an "array"?

Asked

Viewed 148 times

12

In an answer given to a question I asked here on the site, I fixed a user who wrote "array" when referring to a Python "list".

I did this because it is a common nomenclature to be used in Python, although I know that the list Python is very similar to the array of other languages (such as Javascript, for example).

But technically, it would be wrong to say "array" when we are talking about a Python "list"?

And if you look at the functionality, there is difference between a "list" and a "array"?

Note: I chose not to consider array PHP, because in this language array be something more exotic compared to other languages that use this term.

1 answer

12


Yes, technically it is wrong - and it is worth commenting when the terms are used without differentiation.

The first factor is that exist Python arrays - both in the standard library, in the module array, as the native object bytearray. (And the much used numpy arrays).

And the second factor is that in general, when we talk about Array programming in general, without being talking about a specific language, we refer to a pre-allocated data structure with a fixed size.

Even though in other dynamic languages what is called an array in general does not refer to something like this - with fixed size - in programming logic,and in many languages, the distinction does exist. And in this sense the Python lists are quite different from arrays because there is not even a syntax to create them with a fixed size, pre-defined (and in the case of multi-dimensional arrays, there is not even an obvious way, if you want to mimic the behavior with lists).

It does not prevent that in informal conversations and even occasionally in written form, where it is dealing with data that will be used in the front end by javascript and in the back by Python, someone says array. Even though this data will be exchanged in JSON structures, where their name is Array, because of Javascript inheritance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.