Python gives you powerful ways to store and organize data. In this post, youโll learn how to work with three of the most important data structures:
- Lists
- Tuples
- Dictionaries
You’ll also build a simple contact book and learn how to use AI tools like ChatGPT to generate and explain real-world data examples.
๐ Lists โ Ordered, Mutable Collections
A list is a collection of items in a specific order. You can change them, add to them, and remove items.
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple
fruits.append("orange") # Add to the list
print(fruits)
Useful list functions:
len(fruits)
fruits.remove("banana")
fruits.sort()
๐ Tuples โ Ordered, Immutable Collections
Tuples are like lists, but you canโt change them after theyโre created.
colors = ("red", "green", "blue")
print(colors[1]) # Output: green
Use a tuple when your data shouldnโt change.
๐ Dictionaries โ Key/Value Pairs
Dictionaries store data using keys and values โ perfect for things like user info, configuration settings, or contact lists.
person = {
"name": "Alice",
"age": 30,
"is_student": False
}
print(person["name"]) # Output: Alice
Add or update data:
person["email"] = "alice@example.com"
Loop through it:
for key, value in person.items():
print(key, ":", value)
๐ค AI Tip: Use ChatGPT to Simulate Data
Ask:
โGenerate a Python dictionary of 5 fake users with name, age, and email.โ
Youโll get a quick dataset to practice with โ great for building projects and testing logic!
๐ Mini Project: Contact Book (CLI)
Hereโs a small project you can build and expand:
contacts = {}
while True:
name = input("Enter contact name (or 'q' to quit): ")
if name == 'q':
break
phone = input("Enter phone number: ")
contacts[name] = phone
print("\nYour Contacts:")
for name, phone in contacts.items():
print(f"{name}: {phone}")
Bonus: Ask ChatGPT how to save this to a file or add edit/delete features!
๐ฏ Practice Challenge
Create a program that:
- Uses a list to store 5 student names
- Uses a dictionary to assign each student a random grade (0โ100)
- Prints each student and their grade
- Calculates and prints the class average
Ask ChatGPT: โHow can I sort this dictionary by grade?โ
๐ Free Learning Resources
- ๐ Python Lists โ W3Schools
- ๐ Python Dictionaries โ Real Python
- ๐ Python Tuples โ Programiz
- ๐ ChatGPT: Generate mock data, build mini-apps, or review your code
๐ Coming Up in Part 6โฆ
Next time, weโll unlock the power of functions and modules โ so you can organize your code like a pro and reuse it across projects. We’ll also explore how AI can help write cleaner, more modular Python code.