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.
50 lines
1.2 KiB
50 lines
1.2 KiB
#encoding: utf-8
|
|
import re
|
|
|
|
def read_vornamen(filename):
|
|
dict = {}
|
|
# Der Zähler dient nur dazu, die erste Zeile zu überspringen
|
|
count = 0
|
|
pattern_csv = re.compile(';')
|
|
|
|
|
|
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 = pattern_csv.split(zeile.strip())
|
|
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
|
|
|
|
|