4 ms·
Code sample 3 says, "Lists (known as arrays in other languages)", etc. Maybe a small point, but this could be confusing. Python lists are not what are usually m
by leephillips 13y ago
Code sample 3 says, "Lists (known as arrays in other languages)", etc. Maybe a small point, but this could be confusing. Python lists are not what are usually meant by "arrays", and in fact Python provides an array module in its standard library (and there is numpy, which provides more array stuff).
Since much of the "slow" Python code out there is slow at least in part due to use of inappropriate data types, it might be best not to start beginners off by mixing these things up.
- wyuenho 13y agoThey are not linked lists. They aren't that slow. The `arrays` module gives you extra typed arrays for numerical computations.
- scott_s 13y agoThey're pretty close. They provide random access, are backed by contiguous memory, and the syntax behind their use is similar to arrays in other languages.
- akx 13y agoPython lists are backed by contiguous memory of pointers to other objects, mind.
- ithkuil 13y agoThat's because there aren't unboxed primitive values in the language. Even a local integer variable contains a pointer to the integer. This is orthogonal to whether a container is a list or an array though.
- scott_s 13y agoYes, lists in Python are going to be implemented in C as arrays of PyObject pointers. Which is why numpy has their own arrays - they want arrays of int32, float64, etc.
- _ZeD_ 13y agoI think the "array" notion is just to differentiate from the "cons sequence" (or linked-list) notion of the lisp family lists
- jjoonathan 13y agoNothing trips up beginners like slow code.
- pekk 13y agoBeginners have no idea about the connotation of 'numpy array'. Talk about premature optimization.