By: Python Documentation Team Viewed: 161 times Printer Friendly Format
Lists are equivalent to C or Pascal arrays in their time complexity; the primary difference is that a Python list can contain objects of many different types.
["this", 1, "is", "an", "array"]
The array module also provides methods for creating arrays of fixed types with compact representations, but they are slower to index than lists. Also note that the Numeric extensions and others define array-like structures with various characteristics as well.
To get Lisp-style linked lists, you can emulate cons cells using tuples:
lisp_list = ("like", ("this", ("example", None) ) )
If mutability is desired, you could use lists instead of tuples. Here the analogue of lisp car is lisp_list and the analogue of cdr is lisp_list. Only do this if you’re sure you really need to, because it’s usually a lot slower than using Python lists.
Most Viewed Articles (in Python )
Latest Articles (in Python)
Comment on this tutorial
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews