16/ Lists: Adding and changing elements

cities = ["Atlanta", "Baltimore", "Chicago", "Denver", "Los Angeles", "Seattle"]
cities.append("New York")
cities = cities + ["Dubuque", "New Orleans"]
todays_tasks = []
todays_tasks = todays_tasks + ["Walk dog", "Buy groceries"]

cities.insert(0, "New York")
# all the other elements have moved down

Coding exercices

17/ Lists: Taking slices out of them

cities = ["Atlanta", "Baltimore", "Chicago", "Denver", "Los Angeles", "Seattle"]
smaller_list_of_cities = cities[2:5]
# first element is included, second is excluded
smaller_list_of_cities = cities[:5]
smaller_list_of_cities = cities[2:]

Coding exercices