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 8846939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:06:41+00:00 2026-06-14T12:06:41+00:00

For example: {datetime.date(2000, 1, 15): [1], datetime.date(2000, 1, 14): [5], datetime.date(2000, 1, 3): [4],

  • 0

For example:

{datetime.date(2000, 1, 15): [1],
 datetime.date(2000, 1, 14): [5],
 datetime.date(2000, 1, 3): [4],
 datetime.date(2005, 1, 10): [2],
 datetime.date(2005, 1, 16): [4],
 datetime.date(2005, 1, 5): [2]}

to just:

{(2000, 1): [10], (2005,1): [8]}

basically omitting the day, and adding the values. I can’t seem to figure out how to remove datetime.date.

  • 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-06-14T12:06:41+00:00Added an answer on June 14, 2026 at 12:06 pm

    “one-line”r:

    newdict = {
        (key.year, key.month): sum(
            v[0] for k, v in olddict.iteritems()
            if (key.year, key.month) == (k.year, k.month)
        )
        for key in olddict
    }
    
    >>> newdict
    {(2000, 1): 10, (2005, 1): 8}
    

    This might be a little less efficient than 0605002’s answer.


    Or a more conventional solution:

    from collections import defaultdict
    
    newdict = defaultdict(lambda: [0])
    for key in olddict:
        newdict[(key.year, key.month)][0] += olddict[key][0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I calculate date difference between two dates in years? For example: (Datetime.Now.Today()
I start out with date strings: from operator import itemgetter import datetime as DT
Simplified example: [HttpGet] public ActionResult Report(DateTime? date) { if (!date.HasValue) { date = DateTime.Now;
Let's start with a simple example class: public class Foo { public DateTime Date
I have a dictionary of the example: E = 527:{ ('GENERAL MOTORS CORP.', datetime.date(1,
Does anyone have any example on how to put a date time picker inside
For example: DateTime date1 = new DateTime(1955, 12, 12); DateTime date2 = new DateTime(1967,
Using the example code included in the man page for DateTime::Astro::Sunrise , I'm getting
I found an example in MSDN for string to datetime conversion. But it doesn't
how would I format a datetime string received from MySQL? For example, when I

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.