Python. A bit less elegant than some of the other python versions already posted but the same idea using set theory
n=0checkset=set()withopen('input.txt','r')asin_file:forlinin_file:ifl.strip()=='':n+=len(checkset)checkset.clear()else:checkset.update((cforcinl.strip()))ifl.strip()!='':n+=len(checkset)print(f"Part 1: total is {n}")checkset=set()new_group=Truen=0withopen('input.txt','r')asin_file:forlinin_file:ifl.strip()=='':n+=len(checkset)checkset.clear()new_group=Trueelse:ifnew_group:checkset.update((cforcinl.strip()))new_group=Falseelse:# must be in every person: equivalent to set intersection
checkset.intersection_update((cforcinl.strip()))ifl.strip()!='':n+=len(checkset)print(f"Part 2: total is {n}")
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python. A bit less elegant than some of the other python versions already posted but the same idea using set theory