Python Forum
Summing up set elements(HH:MM:SS)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Summing up set elements(HH:MM:SS)
#5
It depends what you want. if one wants whole timedelta in seconds then .total_seconds() should be used instead of .seconds:

add_time_2 = {"23:00:15", "6:15:15", "5:15:15"}

total = sum(map(convert, add_time_2), timedelta())

print(total)

# output -> 1 day, 10:30:45

print(total.total_seconds())

# output -> 124245.0 

time = total.total_seconds()

hours, reminder   = divmod(int(time), 3600)
minutes, seconds = divmod(reminder, 60)
print(f'the total time is {hours}:{minutes}:{seconds}')

# output -> the total time is 34:30:45
tester_V likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Summing up set elements(HH:MM:SS) - by tester_V - Dec-21-2022, 06:44 AM
RE: Summing up set elements(HH:MM:SS) - by tester_V - Dec-21-2022, 06:22 PM
RE: Summing up set elements(HH:MM:SS) - by perfringo - Dec-22-2022, 10:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,248 May-17-2022, 11:38 AM
Last Post: Larz60+
  Summing up rows and columns plumberpy 3 2,313 Aug-18-2021, 05:46 AM
Last Post: naughtyCat
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,651 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  Grouping and summing of dataset jef 0 1,671 Oct-04-2020, 11:03 PM
Last Post: jef
  Summing a list of numbers Oldman45 6 2,953 Jul-12-2020, 05:30 PM
Last Post: Oldman45
  Merge 2 dataframes but avoid double summing of rows? vinaysalian17 0 1,877 Jun-03-2020, 01:48 AM
Last Post: vinaysalian17
  filtering and summing data in a text file apexman 3 3,172 Mar-18-2019, 09:25 PM
Last Post: ichabod801
  summing digits of a number Megabeaz 3 2,694 Jun-29-2018, 02:55 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020