A list is an ordered, mutable collection. Lists can contain any type of element and allow duplicates.
You can:
my_list[0]my_list.append("new")my_list.insert(1, "inserted")my_list.remove("apple")my_list.pop()my_list.sort()list1 + list2 or list1.extend(list2)A tuple is like a list, but it is immutable (cannot be changed).
You can:
my_tuple[0]new_tuple = t1 + t2a, b = (1, 2)len(my_tuple)my_tuple.count(value)A set is an unordered collection of unique elements.
You can:
my_set.add(x)my_set.remove(x) or discard(x)x in my_setA dictionary is a collection of key-value pairs. Keys must be unique.
You can:
student["name"]student["age"] = 21student["grade"] = "A"student.pop("age")for k, v in student.items()Prompt: Create a program that stores a list of students. Each student is a dictionary with keys name and grades (a list). Then, print the average grade for each student.
Target Output:
Alice: 87.5 Bob: 91.5
Ask the AI if you need help understanding or want to dive deeper in any topic