in generalwhen storing structured data on diskit is good idea to put lot of thought into how it is stored one of the reasons myriad database systems exist is that if someone else has put this thought into how data is storedyou don' have to we'll be looking at some data serialization mechanisms in the next but for this examplelet' keep it simple and go with the first solution that could possibly work the data format have in mind is to store each -mail address followed by spacefollowed by comma-separated list of groups this format seems reasonableand we're going to go with it because data formatting isn' the topic of this howeverto illustrate just why you need to think hard about how you format data on disklet' highlight few problems with the format firstthe space character is technically legal in -mail addresses most -mail providers prohibit it (with good reason)but the specification defining -mail addresses says an -mail can contain space if it is in quotation marks if we are to use space as sentinel in our data formatwe should technically be able to differentiate between that space and space that is part of an -mail we're going to pretend this isn' truefor simplicity' sakebut real-life data encoding is full of stupid issues like this secondconsider the comma-separated list of groups what happens if someone decides to put comma in group nameif we decide to make commas illegal in group nameswe should add validation to ensure this to our add_to_group method for pedagogical claritywe'll ignore this problem too finallythere are many security implications we need to considercan someone get themselves into the wrong group by putting fake comma in their -mail addresswhat does the parser do if it encounters an invalid filethe takeaway from this discussion is to try to use data-storage method that has been field testedrather than designing your own data serialization protocol there are ton of bizarre edge cases you might overlookand it' better to use code that has already encountered and fixed those edge cases but forget thatlet' just write some basic code that uses an unhealthy dose of wishful thinking to pretend this simple data format is safeemail @mydomain com group ,group email @mydomain com group ,group the code to do this is as followsdef save(self)with open(self data_file' 'as filefor emailgroups in self email_map items()file write