Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create sort_contacts function
- # Take a DICTIONARY of contacts AS A PARAMETER
- def sort_contacts(sorted_list):
- #the code below converts the dictionary to an unsorted list
- sorted_list = {"Horney, Karen": ("1-541-656-3010", "karen@psychoanalysis.com"),
- "Welles, Orson": ("1-312-720-8888", "orson@notlive.com"),
- "Freud, Anna": ("1-541-754-3010", "anna@psychoanalysis.com")}
- return (list(sorted_list.items()))
- # Return a SORTED LIST of the contacts where each contact is a TUPLE
- mylist = [('Welles, Orson', '1-312-720-8888', 'orson@notlive.com'),
- ('Freud, Anna', '1-541-754-3010', 'anna@psychoanalysis.com'),
- ('Horney, Karen', '1-541-656-3010', 'karen@psychoanalysis.com'),]
- mylist.sort()
- print (mylist)
- # The code below is just for your testing purposes. Make sure you pass all the tests.
- from test import testEqual
- #testEqual(sort_contacts({"Horney, Karen": ("1-541-656-3010", "karen@psychoanalysis.com"),
- # "Welles, Orson": ("1-312-720-8888", "orson@notlive.com"),
- # "Freud, Anna": ("1-541-754-3010", "anna@psychoanalysis.com")}), [('Freud, Anna', '1-541-754-3010',
- # 'anna@psychoanalysis.com'), ('Horney, Karen', '1-541-656-3010', 'karen@psychoanalysis.com'),
- # ('Welles, Orson', '1-312-720-8888', 'orson@notlive.com')])
- #testEqual(sort_contacts({"Summitt, Pat": ("1-865-355-4320", "pat@greatcoaches.com"),
- # "Rudolph, Wilma": ("1-410-5313-584", "wilma@olympians.com")}),
- # [('Rudolph, Wilma', '1-410-5313-584', 'wilma@olympians.com'),
- # ('Summitt, Pat', '1-865-355-4320', 'pat@greatcoaches.com')])
- #testEqual(sort_contacts({"Dinesen, Isak": ("1-718-939-2548", "isak@storytellers.com")}),
- # [('Dinesen, Isak', '1-718-939-2548', 'isak@storytellers.com')])
- #testEqual(sort_contacts({"Rimbaud, Arthur": ("1-636-555-5555", "arthur@notlive.com"),
- # "Swinton, Tilda": ("1-917-222-2222", "tilda@greatActors.com"),
- # "Almodovar, Pedro": ("1-990-622-3892", "pedro@filmbuffs.com"), "Kandinsky, Wassily":
- # ("1-333-555-9999", "kandinsky@painters.com")}), [('Almodovar, Pedro', '1-990-622-3892',
- # 'pedro@filmbuffs.com'), ('Kandinsky, Wassily', '1-333-555-9999', 'kandinsky@painters.com'),
- # ('Rimbaud, Arthur', '1-636-555-5555', 'arthur@notlive.com'), ('Swinton, Tilda',
- # '1-917-222-2222', 'tilda@greatActors.com')])
Add Comment
Please, Sign In to add comment