# How to find who is has the longest meeting length?

https://app.dataquest.io/m/353/working-with-dates-and-times-in-python/10/summarizing-appointment-lengths

Hi! If i want to also find our who has the min length and who has the max length, how to write the code? Thank you.

Hello, you can add this code below the code you’ve written for the same screen:

``````min_max_names = {}

for row in potus:
end_date = row
start_date = row
name = row
length = end_date - start_date
if length == min(appt_lengths):
min_max_names["minimum"] = name
elif length == max(appt_lengths):
min_max_names["maximum"] = name``````
1 Like

Hi @dilarakrby, thank you for helping. Could you help interpret the code? what is the logic here? if i want to see who has the longest meeting length in each month, should i take the month period out first then find the min and the max? i have the basic idea, but don’t have the logic to write the code. Thank you in advance.

Hello,

When you’re looking for the person with the longest visiting time for a certain month, you’ll be able to get desired result doing these:

1. Forming an empty dictionary, like above, for storing the names with the longest visits per each month you wish to use.
2. Inside the for loop, create an if statement to mask the results to the desired month.
3. Check the dictionary key for the desired month to see if the value we have in this row is higher or not. Since this can raise an error if the key doesn’t already exist, we’ll use a try statement. We will also extract the values in hours and round this number to two digits.
4. If the length of visit in this row is longer, we’ll change the value of the corresponding key into this one.

Let’s do it for June:

``````max_length = {}

for row in potus:
start_date = row
name = row
length = end_date - start_date
if start_date.month == 6: #Since June is the 6th month
try:
if max_length["June"] < round(length.seconds / 3600, 2):
max_length["June"] = round(length.seconds / 3600, 2)
except:
max_length["June"] = round(length.seconds / 3600, 2)
``````

This code returns our max_length dictionary as:
{‘June’: 15.48}

3 Likes