Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def animal_locator(places):
- newdict = {}
- for city in places:
- numtup = len(places[city])
- num = 0
- while num < numtup:
- if places[city][num][0] not in newdict:
- newlist = []
- newtup = (places[city][num][1], city)
- newlist.append(newtup)
- for city1 in places:
- if city1 != city:
- for tup in places[city1]:
- if tup[0] == places[city][num][0]:
- tupnew = (tup[1], city1)
- newlist.append(tupnew)
- newlist.sort(reverse=True)
- count = 0
- newlist2 = []
- for tup in newlist:
- newlist2.append(tup[1])
- count += tup[0]
- newtup = (newlist2, count)
- newdict[places[city][num][0]] = newtup
- num += 1
- return newdict
- 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)]}
- animal_dict1 = animal_locator(zoo_location1)
- print(animal_dict1)
Add Comment
Please, Sign In to add comment