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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:00:07+00:00 2026-05-13T10:00:07+00:00

Using Python… How can I get a list of the days in a specific

  • 0

Using Python…

How can I get a list of the days in a specific week?

Something like…

{
'1' : ['01/03/2010','01/04/2010','01/05/2010','01/06/2010','01/07/2010','01/08/2010','01/09/2010'],  
'2' : ['01/10/2010','01/11/2010','01/12/2010','01/13/2010','01/14/2010','01/15/2010','01/16/2010'] 
}

The key of the dictionary in this example would be the week number.

  • 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-13T10:00:07+00:00Added an answer on May 13, 2026 at 10:00 am

    Beware! If you want to define YOUR OWN week numbers, you could use the generator expression provided in your first question which, by the way, got an awesome answer). If you want to follow the ISO convention for week numbers, you need to be careful:

    the first calendar week of a year is
    that one which includes the first
    Thursday of that year and […] the
    last calendar week of a calendar year
    is the week immediately preceding the
    first calendar week of the next
    calendar year.

    So, for instance, January 1st and 2nd in 2010 were NOT week one of 2010, but week 53 of 2009.

    Python offers a module for finding the week number using the ISO calendar:

    Example code:

    h[1] >>> import datetime
    h[1] >>> Jan1st = datetime.date(2010,1,1)
    h[1] >>> Year,WeekNum,DOW = Jan1st.isocalendar() # DOW = day of week
    h[1] >>> print Year,WeekNum,DOW
    2009 53 5
    

    Notice, again, how January 1st 2010 corresponds to week 53 of 2009.

    Using the generator provided in the previous answer:

    from datetime import date, timedelta
    
    
    def allsundays(year):
        """This code was provided in the previous answer! It's not mine!"""
        d = date(year, 1, 1)                    # January 1st                                                          
        d += timedelta(days = 6 - d.weekday())  # First Sunday                                                         
        while d.year == year:
            yield d
            d += timedelta(days = 7)
    
    Dict = {}
    for wn,d in enumerate(allsundays(2010)):
        # This is my only contribution!
        Dict[wn+1] = [(d + timedelta(days=k)).isoformat() for k in range(0,7) ]
    
    print Dict
    

    Dict contains the dictionary you request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Python, how does one parse/access files with Linux-specific features, like ~/.mozilla/firefox/*.default ? I've
Using python and wsgiref.handlers, I can get a single variable from a form with
I'm using Python 2.7. Let's say I have a list like so: string_list =
Using Python regular expressions how can you get a True / False returned? All
Using Python, I'd like to compare every possible pair in a list. Suppose I
Using Python, I'm trying to parse a string like this: hello I am an
Using Python how do you reduce a list of lists by an ordered subset
Using Python module re, how to get the equivalent of the \w (which matches
Using Python I would like to find the date object for last Wednesday. I
Using python's optparse module I would like to add extra example lines below the

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.