I need to take the first name as the key and the other names in the first block as the values, ie, list of strings.
Adding to a dictionary is pretty straight forward (code is not tested)
first_name_dict = {}
f = open('profiles.txt', 'r').readlines()
for line in f:
line = line.strip()
print line
if "," in line:
line_as_list = line.split(',')
if len(line_as_list) > 1:
first_name = line_as_list[1].strip()
last_name = line_as_list[0].strip()
print " ", first_name, last_name
if first_name in first_name_dict:
first_name_dict[first_name].append(last_name)
else:
first_name_dict[first_name]=[last_name]
print first_name_dict
Are members of the group the name before or after "Flying Club", etc. In any case you want to store the names in a list if there is a comma, and do something with that list when there isn't a comma in the record.