Lists
# Lists are ordered, changeable and allow for duplicates
# Define a list
list1 = ["A", "B", "C", "D", "E", "F"]
# Index a list
print(list1[0])
# Index nested lists
print(list1[3][0])
# Change value at index 0
list1[0] = "X"
# Delete value at index
del list1[0]
# Insert value at index
list1.insert(0, "A")
# Append at the end of list
list1.append("G")
# Find max and min value in list
print(max(list1))
print(min(list1))
# Reverse list
list1.reverse()
print(list1)
# Take list back to normal order
list1 = list[::-1]
print(list1)
# Count how many values in list
print(list1.count("A"))
# Pop function to remove and return last object
list1.pop()
# Extend list
list3 = ["H", "I", "J"]
list1.extend(list3)
# Clear list
list1.clear()
# Sort list
list4 = [8, 12, 5, 6, 17, 2]
list4.sort()
# Reverse sort
list4.sort(reverse=True)
# Copy data to a new list
list5 = list4.copy()
Last updated