Question: In python, please make the functions (population_count_for_a_region) (area_count_for_a_region) and (list_of_all_languages) as its described in each function, the population is the second element in each list
In python, please make the functions (population_count_for_a_region) (area_count_for_a_region) and (list_of_all_languages) as its described in each function, the population is the second element in each list and the area is the third element the language is the forth element.
this is the code:
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(list): dict_temp = {}#empty dictionary # for loop to iterate every list in list for i in list: # if key persent in dictionary increment else add key if i[3] in dict_temp.keys(): dict_temp[i[3]] += 1 else: dict_temp[i[3]] = 1
# printing dictionary value for key,value in dict_temp.items(): print(f"{key} : {value}")
# reading data from file file_data = open("data_short2.txt","r") file_data_as_list =[] # converting to list of lists for i in file_data.readlines(): i = i.strip() file_data_as_list.append(i.split(","))
most_frequent(file_data_as_list)
#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: item_parts = item.strip().split(',') region = item_parts[0] regions.add(region) regions = list(regions) return regions
l = ["Australia,23696900,7692024,en,Oceania ", "Austria,8527230,83871,de,Europe ", "Azerbaijan,9552500,86600,az,Asia ", "Bulgaria,7245677,110879,bg,Europe "] print(unique_regions(l))
#Function that finds the total population of a given region def population_count_for_a_region(region,list_of_all_countries_with_data): ''' This function receives a list that looks like ["Australia,23696900,7692024,en,Oceania ", "Austria,8527230,83871,de,Europe ", "Azerbaijan,9552500,86600,az,Asia ", "Bulgaria,7245677,110879,bg,Europe "] and returns the sum of (23696900 + 8527230 + 9552500 + 7245677) ''' pass
#Function that finds the total area of a given region def area_count_for_a_region(region,list_of_all_countries_with_data): ''' This function is similar to the function population_count_for_a_region for area. ''' pass
#Function that finds list of all languages and the most spoken language def list_of_all_languages(region,list_of_all_countries_with_data): ''' ["Australia,23696900,7692024,en,Oceania ", "Austria,8527230,83871,de,Europe ", "Azerbaijan,9552500,86600,az,Asia ", "Bulgaria,7245677,110879,bg,Europe "] and returns ['en', 'de', 'az', 'bg'] ''' pass
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
