Computing with Data

elgeish
181.5K views

Lists

Lists are similar to tuples, but they're mutable, and they're defined using square brackets (or the built-in function list):

a = [1, 2, 3] # list containing three integers
b = [a, "hello"] # list containing a list and a string
b.append(4) # modify existing list by appending an element
print(a)
print(b)
# Example: inserting, removing, and sorting elements
a = [1, 2, 3]
a.insert(1, 100) # insert 100 before index 1
print(a)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX