Skip to content
Snippets Groups Projects
Commit 5b6ef2d3 authored by Lennart Kemmerling's avatar Lennart Kemmerling
Browse files

aufgabe 6 hochgeladen

parent cc09ff6a
Branches
Tags aufgabe6
No related merge requests found
import csv
from collections import defaultdict
country_pop = []
csvfile = open("oopse\\worldcities.csv", encoding="utf8")
reader = csv.DictReader(csvfile,delimiter=";")
for row in reader:
country_pop.append((row['country'],row['population']))
country_pop_dict = defaultdict(list)
for country, pop in country_pop:
country_pop_dict[country].append(pop)
for i in country_pop_dict.keys():
total_pop = 0
for l in range(len(country_pop_dict[i])):
if country_pop_dict[i][l] != '':
total_pop = total_pop + int(country_pop_dict[i][l])
country_pop_dict[i] = total_pop
country_pop_dict = sorted(country_pop_dict.items(), key=lambda kv: (kv[1], kv[0] ),reverse=True)
print(country_pop_dict)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment