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.