All pastes #469722 Raw Edit

Anonymous

public python v1 · immutable
·published 2007-05-03 21:26 UTC
rendered paste body
# Database thingy# Simply store records as dictionaries with name, address and phone-number# fields and store them in a main database (a list)# construct record dictionary and add to database listdef AddRecord(name, address, phone_number):    entry = {'name': name, 'address': address, 'phone-number': phone_number}    database.append(entry)# search for phrase in name, address or phone-number of each record# and print if founddef SearchForRecord(phrase):    for record in database:        if phrase in record.values():            PrintRecord(record)# print a recorddef PrintRecord(recordname):    print recordname['name']    print recordname['address']    print recordname['phone-number']    print# show all recordsdef ListRecords():    for record in database:        PrintRecord(record)# delete record matching phrasedef DeleteRecord(phrase):    for record in database:        if phrase in record.values():            database.remove(record)# make a new databasedatabase = list()AddRecord("Ernie", "Boleveien 22", "99339922")AddRecord("Olav", "Boleveien 4", "99339922")DeleteRecord("Olav")ListRecords()