Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6157861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:51:30+00:00 2026-05-23T20:51:30+00:00

How to add The following timestamps month wise in python 2.4 i.e, all the

  • 0

How to add The following timestamps month wise in python 2.4 i.e, all the timestamps occurring in month 3 should be added together.

For example: the result should be like on 2011-03 total timestamp is 1:00:45 and so on for other months..

2011-03-07  0:27:41
2011-03-06  0:13:41
2011-03-08  0:17:40
2011-03-04  0:55:40
2011-05-16  0:55:40
2011-05-18  0:55:40
2011-07-16  0:55:40
2011-07-17  0:55:40
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:51:31+00:00Added an answer on May 23, 2026 at 8:51 pm

    How about this:

    import datetime
    import re
    from collections import defaultdict
    months = defaultdict(int)
    # months = {}  # for Python 2.4
    with open("test.txt") as timestamps:
        for line in timestamps:
            month = line[:7]
            time = re.search(r"(\d+):(\d+):(\d+)", line)
            if time:
                 seconds = int(time.group(1))*3600 + \
                           int(time.group(2))*60 +   \
                           int(time.group(3))
                 months[month] += seconds
                 # if month in months:          # Python 2.4
                 #     months[month] += seconds
                 # else:
                 #     months[month] = seconds
    for month in sorted(months.keys()):
        print("Times for {}: {}".format(month, 
                                        datetime.timedelta(seconds=months[month])))
    

    Output:

    Times for 2011-03: 1:54:42
    Times for 2011-05: 1:51:20
    Times for 2011-07: 1:51:20
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add the following MIME type to a site run by
I would like to do something like the following: def add(a, b): #some code
I have a question about Rails database. Should I add index to all the
I am trying to add the following method to the Math class in Ruby
I have a strange one. Create a new form. Then add the following function
I want to do the following: 1: Add two dropdown list in the register.aspx
The following code will add the categories selector widget to the WordPress Page editor
The following query works as long as I can add DataRelations. However, the relation
Am using the following notation to add a primary key to a table: ALTER
I add many check boxes to the excel sheet programaticaly using the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.