When it comes to the Python "list", is it wrong to call "array"?

6

In a response to a question I asked here on the site, I corrected a user who wrote "array" when referring to a Python "list".

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

p>

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

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

Note : I preferred not to consider the array of PHP, because in this language the array is something more exotic if compared to other languages that use this term.

    
asked by anonymous 12.12.2016 / 13:46

1 answer

6

Yes, it's technically wrong - and it's worth commenting on when terms are used without differentiation.

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

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

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

It does not stop 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 names are Array, due to the inheritance of Javascript.

    
12.12.2016 / 14:09