You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
11 months ago
|
#encoding: utf-8
|
||
|
|
||
|
def read_vornamen(filename):
|
||
|
dict = {}
|
||
|
# Der Zähler dient nur dazu, die erste Zeile zu überspringen
|
||
|
count = 0
|
||
|
|
||
|
dict['mädchen'] = 0
|
||
|
dict['jungs'] = 0
|
||
|
dict['divers'] = 0
|
||
|
with open(filename,'r') as f:
|
||
|
for zeile in f:
|
||
|
if count >0:
|
||
|
# einzelne Zeile in seine Bestandteile zerlegen
|
||
|
splitted = zeile.strip().split(';')
|
||
|
anzahl = splitted[0]
|
||
|
vorname = splitted[1]
|
||
|
geschlecht= splitted[2]
|
||
|
position = splitted[3]
|
||
|
|
||
|
if geschlecht == 'w':
|
||
|
dict['mädchen'] += 1
|
||
|
elif geschlecht == 'm':
|
||
|
dict['jungs'] += 1
|
||
|
else:
|
||
|
dict['divers'] += 1
|
||
|
|
||
|
|
||
|
|
||
|
data = {}
|
||
|
data['vorname'] = vorname
|
||
|
data['anzahl'] = int(anzahl)
|
||
|
data['geschlecht'] = geschlecht
|
||
|
data['position'] = position
|
||
|
if vorname not in dict:
|
||
|
dict[vorname] = data
|
||
|
else:
|
||
|
# doppelte Einträge summieren wir auf.
|
||
|
e = dict[vorname]
|
||
|
e['anzahl'] = int(anzahl) + (e['anzahl'])
|
||
|
count +=1
|
||
|
|
||
|
gesamt = dict['jungs'] + dict['mädchen'] + dict['divers']
|
||
|
|
||
|
dict['gesamt'] = gesamt
|
||
|
return dict
|
||
|
|