Computer Science > Lab Experiment > Michigan State University - CSE CSE231lab09b.py (All)
# Define the function to create a dictionary #and store the values as dictionaries and sets def build_map(continent_file, city_file): Data_map = {} # read the continents.txt file and #create the ... dictionary of continents and countries continent_country_content = continent_file.readlines() continent_country_content = continent_country_content[1:] #Read each line from the continent_file for line in continent_country_content: # Remove the header of the file continent_list = line.strip().split('\t',1) continent = continent_list[0].strip() country = continent_list[1].strip() #check whether continents exist in the dictionary #or not if continent not in Data_map.keys(): Data_map[continent] = {country : set()} elif country not in Data_map[continent].keys(): Data_map[continent][country] =set() # read the cities.txt file and add cities to the countries #included in the dictionary country_city_content = city_file.readlines() country_city_content = country_city_content[1:] for line in country_city_content: # Remove the header of the file country_list = line.strip().split('\t',1) country = country_list[0].strip() [Show More]
Last updated: 1 year ago
Preview 1 out of 3 pages
Instant download
Buy this document to get the full access instantly
Instant Download Access after purchase
Add to cartInstant download
Connected school, study & course
About the document
Uploaded On
Mar 29, 2021
Number of pages
3
Written in
This document has been written for:
Uploaded
Mar 29, 2021
Downloads
0
Views
73
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·