'Compare 2 dictionaries for matching times
I have two dictionaries both containing times, one of events on each day, and the other with a students free times during the day. I am trying to match them up but it seems as though I have done something wrong as they wont match. my first dictionary is this :
event_dates = {} #dictionary to store event dates and time
df = pd.read_html('https://www.dcu.ie/students/events')[0]['Event date']
df = df.str.replace('([a-zA-Z]+ \d+, |\s+(?=\s))', '')
df = df.str.split("-")
event_dates.update(df)
this is just something to see all the events times :
for key in event_dates.values():
key = key[0]
print("Event starts at:", key)
and this is how it comes out
Event starts at: 09:00
Event starts at: 12:45
Event starts at: 17:00
Event starts at: 13:00
Event starts at: 13:15
Event starts at: 13:00
Event starts at: 13:00
Event starts at: 13:00
Event starts at: 14:00
Event starts at: 17:00
Event starts at: 13:00
Event starts at: 13:15
Event starts at: 18:00
Event starts at: 13:00
Event starts at: 13:00
Event starts at: 13:00
Event starts at: 15:00
Event starts at: 13:00
Event starts at: 13:00
Event starts at: 13:00
for my other dictionary
free_times = []
for column in df3:
free_times.append({column:df3[df3[column].isna()].index.drop_duplicates().to_list()})
this is an example of how it comes out
[{'Mon': ['8:00', '10:00', '12:00', '13:00', '15:00', '18:00', '19:00', '20:00', '21:00']}, {'Tue': ['8:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00']}, {'Wed': ['8:00', '11:00', '12:00', '13:00', '14:00', '15:00', '18:00', '19:00', '20:00', '21:00']}, {'Thu': ['8:00', '9:00', '12:00', '13:00', '17:00', '18:00', '19:00', '20:00', '21:00']}, {'Fri': ['8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00']}]
and this is how i am trying to check them
if key == free_times:
print("There is an event on")
else:
print("There are no events on")
any questions please feel free to ask.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
