# [ ] review and run example
visited_cities = ["New York", "Shanghai", "Munich", "Toyko", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
wish_cities = ["Reykjavík", "Moscow", "Beijing", "Lamu"]
# .extend()
# extending visited_cities list (IN PLACE) by concatenating wish_cities
visited_cities.extend(wish_cities)
print("ALL CITIES",visited_cities)
# [ ] review and run example
visited_cities = ["New York", "Shanghai", "Munich", "Toyko", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
wish_cities = ["Reykjavík", "Moscow", "Beijing", "Lamu"]
# (+) Addition operator for lists creates a (NEW) combined List
all_cities = visited_cities + wish_cities
print("ALL CITIES")
for city in all_cities:
print(city)
# [ ] review and run example
team_a = [0,2,2,2,4,4,4,5,6,6,6]
team_b = [0,0,0,1,1,2,3,3,3,6,8]
print("Team A:", team_a, "\nTeam B:",team_b)
# (+) Addition operator
team_totals = team_a + team_b
print("Team Totals", team_totals)
# [ ] review and run example after running cell above
# .extend()
team_a.extend(team_b)
print("Team_a extended", team_a)
# what happens if you keep running this cell?
# [ ] extend the list common_birds with list birds_seen which you must create
common_birds = ["chicken", "blue jay", "crow", "pigeon"]
birds_seen = ["turkey", "Cardinal", "dove", "sparrow"]
common_birds.extend(birds_seen)
print(common_birds)
# [ ] Create 2 lists zero_nine and ten_onehundred that contain 1-9, and 10 - 100 by 10's.
# [ ] use list addition to concatenate the lists into all_num and print
zero_nine = [1,2,3,4,5,6,7,8,9]
ten_onehundred = [10,20,30,40,50,60,70,80,90,100]
all_num =
# [ ] review and run example
cities_1 = ["Dubai", "Mexico City", "São Paulo", "Hyderabad"]
print("regular", cities_1)
cities_1.reverse()
print("reversed", cities_1)
# [ ] review and run example
all_num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
print("regular list",all_num, "\n")
all_num.reverse()
print("reverse list",all_num, "\n")
num_len = len(all_num)
print("Three Multiple")
for num in all_num:
if num/3 == int(num/3):
print(num)
else:
pass
# [ ] review and run example
# create a list of numbers by casting a range
count_list = list(range(21))
print("before list", count_list)
# and reverse
count_list.reverse()
print("after list", count_list)
# [ ] create and print a list of multiples of 5 from 5 to 100
# { ] reverse the list and print
fives = [5,10,15,20,25,30,35,30,45,50,55,60,65,70,75,80,85,90,95,100]
print(fives)
fives.reverse()
print(fives)
# [ ] Create two lists: fours & more_fours containing multiples of four from 4 to 44
# [ ] combine and print so that the output is mirrored [44, 40,...8, 4, 4, 8, ...40, 44]
fours = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44]
four_more = [4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44]
four_more.reverse()
all_fours = fours + four_more
print(all_fours)
# [ ] review and run example
quiz_scores = [20, 19, 20, 15, 20, 20, 20, 18, 18, 18, 19]
# use .sort()
quiz_scores.sort()
print("quiz_scores:", quiz_scores)
# [ ] review and run example
game_points = [3, 14, 0, 8, 21, 1, 3, 8]
# use sorted()
sorted_points = sorted(game_points)
print("game_points:", game_points)
print("sorted_points:", sorted_points)
# [ ] review and run example
cities_1 = ["Dubai", "Mexico City", "São Paulo", "Hyderabad"]
print("Unsorted", cities_1)
cities_1.sort()
print("Sorted", cities_1)
# [ ] print cites from visited_cities list in alphbetical order using .sort()
# [ ] only print cities that names start "Q" or earlier
visited_cities = ["New York", "Shanghai", "Munich", "Toyko", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
visited_cities.sort()
print(visited_cities)
for city in visited_cities:
if city[0] <= "Q":
print(city)
else:
pass
# [ ] make a sorted copy (sorted_cities) of visited_cities list
# [ ] remove city names 5 characters or less from sorted_cities
# [ ] print visitied cites and sorted cities
visited_cities = ["New York", "Shanghai", "Munich", "Toyko", "Dubai", "Mexico City", "São Paulo", "Hyderabad"]
sorted_cities = sorted(visited_cities)
for city in visited_cities:
if len(city) <= 5:
sorted_cities.remove(city)
else:
pass
print(visited_cities)
print(sorted_cities)
# [ ] build a list (add_animals) using a while loop, stop adding when an empty string is entered
add_animals = []
while True:
animal = input("Enter the name of an animal").title()
if animal != '':
add_animals.append(animal)
else:
break
# [ ] extend the lists into animals, then sort
animals = ["Chimpanzee", "Panther", "Wolf", "Armadillo"]
animals.extend(add_animals)
animals.sort()
# [ ] get input if list should be viewed alpha or reverse alpha and display list
a_or_r = input("Enter 'alpha' for alphabetical order or 'reverse' for reverse order:")
if a_or_r == 'alpha':
print(animals)
else:
animals.reverse()
print(animals)
add_animals = []
while True:
animal = input("Enter the name of an animal and type exit when finished: ").title()
if animal != "exit":
add_animals.append(animal)
else:
break
animals = ["Chimpanzee", "Panther", "Wolf", "Armadillo"]
animals.extend(add_animals)
animals.sort()
a_or_r = input("Enter 'alpha' for alphabetical order list or 'reverse' for reverse order list:")
if a_or_r == 'alpha':
print(animals)
else:
animals.reverse()
print(animals)