Oct-14-2019, 11:37 AM
The existing datastructure (dataset?) and the objective is somewhat unclear for me, but if I would have had file named 'count_data.txt' with following content:
Output:Name,count
abc,1
ABC,2
Abc,1
abc,5
ABC,1
I would just simple brute-force:with open('count_data.txt', 'r') as f: data = list(DictReader(f.readlines())) unique = {row['Name'] for row in data} for name in unique: print(f'{name}: {sum(int(row["count"]) for row in data if row["Name"] == name)}')which will give:
Output:Abc: 1
ABC: 3
abc: 6
As 'data' is list of dictionaries one can use list comprehension for whatever filtering/subtotaling needed.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.