Ravindra BagaleCourses & study guides मराठी Track your progress

3. Python Basics for Data Work

Data Science

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

  1. Create the cities list above.
  2. Append "Pune" again with cities.append("Pune") — lists allow duplicates.
  3. Build managers and 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))