'{{}\nformat(email',join(groups)def load(self)self email_map defaultdict(settrywith open(self data_fileas filefor line in fileemailgroups line strip(split('groups set(groups split(',')self email_map[emailgroups except ioerrorpass in the save methodwe open the file in context manager and write the file as formatted string remember the newline characterpython doesn' add that for us the load method first resets the dictionary (in case it contains data from previous call to loaduses the for in syntaxwhich loops over each line in the file againthe newline character is included in the line variableso we have to call strip(to take it off we'll learn more about such string manipulation in the next before using these methodswe need to make sure the object has self data_file attributewhich can be done by modifying __init__def __init__(selfdata_file)self data_file data_file self email_map defaultdict(setwe can test these two methods in the interpreter as followsm mailinglist('addresses db' add_to_group('friend @example com''friends' add_to_group('family @example com''friends' add_to_group('family @example com''family' save(the resulting addresses db file contains the following linesas expectedfriend @example com friends family @example com friends,family