Guest User

Untitled

a guest
May 5th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. # Create sort_contacts function
  2. # Take a DICTIONARY of contacts AS A PARAMETER
  3. def sort_contacts(sorted_list):
  4.  
  5. #the code below converts the dictionary to an unsorted list
  6. sorted_list = {"Horney, Karen": ("1-541-656-3010", "karen@psychoanalysis.com"),
  7. "Welles, Orson": ("1-312-720-8888", "orson@notlive.com"),
  8. "Freud, Anna": ("1-541-754-3010", "anna@psychoanalysis.com")}
  9. return (list(sorted_list.items()))
  10. # Return a SORTED LIST of the contacts where each contact is a TUPLE
  11. mylist = [('Welles, Orson', '1-312-720-8888', 'orson@notlive.com'),
  12. ('Freud, Anna', '1-541-754-3010', 'anna@psychoanalysis.com'),
  13. ('Horney, Karen', '1-541-656-3010', 'karen@psychoanalysis.com'),]
  14.  
  15. mylist.sort()
  16. print (mylist)
  17.  
  18.  
  19. # The code below is just for your testing purposes. Make sure you pass all the tests.
  20.  
  21. from test import testEqual
  22.  
  23. #testEqual(sort_contacts({"Horney, Karen": ("1-541-656-3010", "karen@psychoanalysis.com"),
  24. # "Welles, Orson": ("1-312-720-8888", "orson@notlive.com"),
  25. # "Freud, Anna": ("1-541-754-3010", "anna@psychoanalysis.com")}), [('Freud, Anna', '1-541-754-3010',
  26. # 'anna@psychoanalysis.com'), ('Horney, Karen', '1-541-656-3010', 'karen@psychoanalysis.com'),
  27. # ('Welles, Orson', '1-312-720-8888', 'orson@notlive.com')])
  28. #testEqual(sort_contacts({"Summitt, Pat": ("1-865-355-4320", "pat@greatcoaches.com"),
  29. # "Rudolph, Wilma": ("1-410-5313-584", "wilma@olympians.com")}),
  30. # [('Rudolph, Wilma', '1-410-5313-584', 'wilma@olympians.com'),
  31. # ('Summitt, Pat', '1-865-355-4320', 'pat@greatcoaches.com')])
  32. #testEqual(sort_contacts({"Dinesen, Isak": ("1-718-939-2548", "isak@storytellers.com")}),
  33. # [('Dinesen, Isak', '1-718-939-2548', 'isak@storytellers.com')])
  34. #testEqual(sort_contacts({"Rimbaud, Arthur": ("1-636-555-5555", "arthur@notlive.com"),
  35. # "Swinton, Tilda": ("1-917-222-2222", "tilda@greatActors.com"),
  36. # "Almodovar, Pedro": ("1-990-622-3892", "pedro@filmbuffs.com"), "Kandinsky, Wassily":
  37. # ("1-333-555-9999", "kandinsky@painters.com")}), [('Almodovar, Pedro', '1-990-622-3892',
  38. # 'pedro@filmbuffs.com'), ('Kandinsky, Wassily', '1-333-555-9999', 'kandinsky@painters.com'),
  39. # ('Rimbaud, Arthur', '1-636-555-5555', 'arthur@notlive.com'), ('Swinton, Tilda',
  40. # '1-917-222-2222', 'tilda@greatActors.com')])
Add Comment
Please, Sign In to add comment