Guest User

Untitled

a guest
Oct 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. def animal_locator(places):
  2. newdict = {}
  3. for city in places:
  4. numtup = len(places[city])
  5. num = 0
  6. while num < numtup:
  7. if places[city][num][0] not in newdict:
  8. newlist = []
  9. newtup = (places[city][num][1], city)
  10. newlist.append(newtup)
  11. for city1 in places:
  12. if city1 != city:
  13. for tup in places[city1]:
  14. if tup[0] == places[city][num][0]:
  15. tupnew = (tup[1], city1)
  16. newlist.append(tupnew)
  17. newlist.sort(reverse=True)
  18. count = 0
  19. newlist2 = []
  20. for tup in newlist:
  21. newlist2.append(tup[1])
  22. count += tup[0]
  23. newtup = (newlist2, count)
  24. newdict[places[city][num][0]] = newtup
  25. num += 1
  26. return newdict
  27.  
  28. zoo_location1 = {'San Diego': [('lion', 4), ('tiger', 2), ('bear', 8)], 'Bronx': [('lion', 20), ('snake', 5), ('tiger', 1)], 'Atlanta': [('lion', 3), ('snake', 2), ('bee', 4500)], 'Orlando': [('bee', 234), ('tiger', 123)]}
  29. animal_dict1 = animal_locator(zoo_location1)
  30. print(animal_dict1)
Add Comment
Please, Sign In to add comment