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

  • Home
  • SEARCH
  • 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 695675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:59:02+00:00 2026-05-14T02:59:02+00:00

I have an array of files. I’d like to be able to break that

  • 0

I have an array of files. I’d like to be able to break that array down into one array with multiple subarrays, each subarray contains files that were created on the same day. So right now if the array contains files from March 1 – March 31, I’d like to have an array with 31 subarrays (assuming there is at least > 1 file for each day).

In the long run, I’m trying to find the file from each day with the latest creation/modification time. If there is a way to bundle that into the iterations that are required above to save some CPU cycles, that would be even more ideal. Then I’d have one flat array with 31 files, one for each day, for the latest file created on each individual day.

My current data structure is just a flat list of file names.

  • 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-14T02:59:02+00:00Added an answer on May 14, 2026 at 2:59 am

    Following up on Messa’s answer, if your structure is like:

    files=[{'date': datetime(2010, 3, 1, 0, 0, 10), 'file': 'foo'}, 
           {'date': datetime(2010, 3, 1, 12, 0, 10), 'file': 'bar'}, 
           {'date': datetime(2010, 3, 2, 3, 5, 10), 'file': 'baz'}, 
           {'date': datetime(2010, 3, 2, 3, 3, 10), 'file': 'foo'}]
    

    try something like:

    from itertools import groupby
    map(lambda x: next(x[1]), 
        groupby(sorted(files, 
                       key=lambda x: x['date'],
                       reverse=True), 
             key=lambda x: datetime(x['date'].year, x['date'].month, x['date'].day)))
    

    which will give you:

    [{'date': datetime.datetime(2010, 3, 2, 3, 5, 10), 'file': 'baz'}, {'date': datetime.datetime(2010, 3, 1, 12, 0, 10), 'file': 'bar'}]
    

    Basically, it first sorts by date in reverse (sorted), then groups by date (groupby), then takes the first element of every group (next[1]).

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

Sidebar

Related Questions

If I have an array that contains multiple FLV files like so: my @src_files
Consider I have an array like the following one: string[] Files = {NO. 1,
I have an array of folders/files that looks like this: Array ( [Root Folder
I have an array (produced by uploading multiple files) that returns this: Array (
I have a function that creates zip files when passed an array of files
I have an array that is a list of files in a folder, I'm
I have an array that stores a few urls of XML files that need
I have an array of images, and two nib files. One nib file has
i have an array of names which have multiple files and folders...now i want
I have a rakefile which uses jsmin to minify the files. one thing that

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.