By: Python Documentation Team Emailed: 1765 times Printed: 2513 times
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.
Be the first one to add a comment
Most Viewed Articles (in Python )
Most Emailed Articles (in Python)