In: Computer Science
python pls
create a function party_place: that search the dictionary and figure out where they party in that day.
For example
def party_place(dict2: dict, date: (int,int,int)):
dict1= {'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0,
300)),
(2000,5,20,720) : ('Baily', 45, 1500, (1500,500)),
(2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) },
'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)),
(2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }}
output
print(party_place(dict1, (2000,5,20,720))
= ['fire1', 'fire2']
print(party_place(dict1, (2000,5,21,720))
= ['fire1']
print(party_place(dict1, (2000,5,22,720))
= []
def party_place(dict2: dict, date: (int, int, int, int)):
# remove last part
date = date[:3]
# list to return
places = []
# iterate over dict2
for place in dict2:
dates = dict2[place]
# remove last part from all dates
dates = [d[:3] for d in dates]
# if given date is present in current place
if date in dates:
# add to places
places.append(place)
return places
dict1 = {'fire1': {(2000, 5, 20, 480): ('Aaron', 25, 300, (0, 300)),
(2000, 5, 20, 720): ('Baily', 45, 1500, (1500, 500)),
(2000, 5, 21, 490): ('Aaron', 35, 500, (1300, 500))},
'fire2': {(2000, 5, 20, 810): ('Baily', 45, 1400, (600, 1600)),
(2000, 5, 20, 930): ('Baily', 43, 1800, (0, 0))}}
print(party_place(dict1, (2000, 5, 20, 720))) # =['fire1', 'fire2']
print(party_place(dict1, (2000, 5, 21, 720))) # =['fire1']
print(party_place(dict1, (2000, 5, 22, 720))) # =[]
.
Screenshot:
Output:
.