Question: This is a python program, please use the #comment to illustrate each step in this program. I will upvote if its right! dont change the

This is a python program, please use the #comment to illustrate each step in this program. I will upvote if its right! dont change the code, if you want an idea of it use this input file: Estonia,1315819,45227,et,Europe Libya,6253000,1759540,ar,Africa Sierra Leone,6205000,71740,en,Africa Denmark,5655750,43094,da,Europe Tuvalu,11323,26,en,Oceania ---- make the code pastable, and with indenting import sys def break_apart(my_string, my_delimiter): split_string=my_string.split(my_delimiter) return split_string # Program to find most frequent # element in a list # Figure out the most spoken language in each region. # for most frequent data in laung def most_frequent(region , list): dict_temp = {} mx = 0 mx_lang = '' for i in list: if i[4] == region: if i[3] not in dict_temp: dict_temp[i[3]] = 0 dict_temp[i[3]] += int(i[1]) if mx <= dict_temp[i[3]]: mx = dict_temp[i[3]] mx_lang = i[3] return mx_lang #Function to identify all the unique regions in the .txt file. def unique_regions(list_of_all_countries_with_data): regions = set() for item in list_of_all_countries_with_data: region = item[0] regions.add(region) regions = list(regions) return regions def population_count_for_a_region(region,list_of_all_countries_with_data): population = 0 for item in list_of_all_countries_with_data: item_region = item[4] if region == item_region: population += int(item[1]) return population #Function that finds the total area of a given region def area_count_for_a_region(region,list_of_all_countries_with_data): area = 0 for item in list_of_all_countries_with_data: item_region = item[4] if region == item_region: area += int(item[2]) return area #Function that finds list of all languages and the most spoken language (most spoken language for extra credit) def list_of_all_languages(region, list_of_all_countries_with_data): languages = set() for item in list_of_all_countries_with_data: if item[4] == region: language = item[3] languages.add(language) languages = list(languages) languages.sort() return languages if __name__ == "__main__": file_name = input('What file do you want to parse?: ') # reading data from file file_data_as_list =[] continents = {} try: file_data = open(file_name,"r") list_of_all_lines = file_data.readlines() # converting to list of lists for i in list_of_all_lines: i = i.strip() file_data_as_list.append(i.split(",")) except: print('File not found.') sys.exit(1) for con in file_data_as_list: continents[con[4]]=1 continents = list(continents) continents.sort() for con in continents: print('Name of Continent: '+con) print('Population: ' + str(population_count_for_a_region(con , file_data_as_list))) print('Area: '+ str(area_count_for_a_region(con,file_data_as_list))) print('List of All Languages: ' + str(list_of_all_languages(con,file_data_as_list))) print('Most spoken language: ' + most_frequent(con,file_data_as_list)) print() 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!