156,671 views
44 votes
44 votes
The following program includes 10 cities that two people have visited. Write a program that creates: 1. A set all_cities that contains all of the cities both people have visited. 2. A set same_cities that contains only cities found in both person1_cities and person2_cit ies. 3. A set different_cities that contains only cities found in only person1_cities or person2_cities. Sample output for all cities: ['Accra', "Anaheim', 'Bangkok', 'Bend', 'Boise', 'Buenos Aires', "Caìro', "Edmonton', 'Lima', "London', 'Memphis', 'Orlando', 'Paris', 'Seoul', 'Tokyo', 'Vancouver', 'Zurich'] NOTE Because sets are unordered, they are printed using the sorted() function here for comparison. 1 person1 cities - ('Edeonton', "Vancouver', 'Parls", 'Bangkok', 'Hend', 'Bolse', 'Mosshis", "Zurlch', "Accra", ", 2 person2,cltles = ("Accra", "Orlando", "Tokyo", "Paris", "Anahein', 'Hienos Aires", "tondon', "Lima", "Seoul", 4 " Use set methods to create sets atl_cities, same _ities, and different_cities. 6." Your solution ges here w 7 in print(sorted(al1_cities)) 9. print(sorted(same_cities)) 10 print(sorted(different_cities))

User Henry Harbeck
by
2.9k points

1 Answer

13 votes
13 votes

Answer:

all_cities = person1_cities.union(person2_cities)

same_cities = person1_cities.intersection(person2_cities)

different_cities = person1_cities.symmetric_difference(person2_cities)

Step-by-step explanation:

User Kassens
by
3.3k points