3. Python Basics for Data Work
3.2 Lists and Dictionaries
cities = ["Pune", "Solapur", "Nashik", "Sambhaji Nagar", "Kolhapur", "Nagpur"]
print(cities[0]) # Pune
print(len(cities)) # 6
# dict: city -> fictional manager
managers = {
"Pune": "Ravindra Bagale",
"Nashik": "Shraddha Bagale",
"Nagpur": "Ruhi Bagale",
}
print(managers["Pune"])
print(managers.get("Satara", "Unknown")) # safe default
Steps in Jupyter
- Create the
citieslist above. - Append
"Pune"again withcities.append("Pune")— lists allow duplicates. - Build
managersand print Nashik’s manager.
What you should see. Indexing starts at 0. .get avoids KeyError.
Try it Yourself
Change the code and press Run. Nothing is saved, so you can experiment freely. Reset brings back the example.
cities = ["Pune", "London", "Nashik", "Berlin", "Chennai"]
cities.append("Tokyo")
print("How many cities:", len(cities))
print("First city:", cities[0])
print("Last two:", cities[-2:])
# Sample fees (made-up numbers for practice)
fees = {"Priya (Pune)": "₹4999", "James (London)": "£79", "Lukas (Berlin)": "€59", "Emily (New York)": "$99"}
for student, fee in fees.items():
print(f"{student:18} pays {fee}")
fees["Meera (Chennai)"] = "₹4999"
print("Students now:", len(fees))
marks = {"Rohan": [72, 88, 91], "Sofia": [65, 79, 84], "Kenji": [90, 93, 87]}
for name, m in marks.items():
print(name, "average =", round(sum(m) / len(m), 1))