Skip to content
UPEEC

Lists

Ordered, mutable sequences — the workhorse collection in Python.

Beginner
Comments 0
readings = [3.2, 3.3, 3.1]
readings.append(3.4)
readings[0]          # 3.2
readings[-1]         # 3.4
len(readings)        # 4
sorted(readings)     # new sorted list
readings.sort()      # sort in place

Lists can hold any mix of types. Appending is fast; inserting or deleting at the front is slow for long lists (use collections.deque for queues).

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.