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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:43:50+00:00 2026-06-16T23:43:50+00:00

I have some Entrys in a python list.Each Entry has a creation date and

  • 0

I have some Entrys in a python list.Each Entry has a creation date and creation time.The values are stored as python datetime.date and datetime.time (as two separate fields).I need to get the list of Entrys sorted sothat previously created Entry comes before the others.

I know there is a list.sort() function that accepts a key function.In this case ,do I have to use the date and time to create a datetime and use that as key to sort()? There is a datetime.datetime.combine(date,time) for this. But how do I specify this inside the sort function?

I tried key = datetime.datetim.combine(created_date,created_time)

but the interpreter complains that the name created_date is not defined

class Entry: 
   created_date = #datetime.date
   created_time  = #datetime.time
   ...

my_entries_list=[Entry1,Entry2...Entry10]
my_entries_list.sort(key = datetime.datetim.combine(created_date,created_time))
  • 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-16T23:43:52+00:00Added an answer on June 16, 2026 at 11:43 pm

    You probably want something like:

    my_entries_list.sort(key=lambda v:
                               datetime.datetime.combine(v.created_date, v.created_time))
    

    Passing datetime.datetime.combine(created_date, created_time) tries to call combine immediately and breaks since created_date and created_time are not available as local variables. The lambda provides delayed evaluation: instead of executing the code immediately, it creates a function that will, when called, execute the specified code and return the result. The function also provides the parameter that will be used to access the created_date and created_time attributes.

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

Sidebar

Related Questions

I have some Python code where I need to call upon a dictionary entry
Have created a Django datetime field 'time' and want to have some comparisions based
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have some code here that uses bitsets to store many 1 bit values
Being new to the python games I seem to have missed out on some
I have some python scripts that run on a daily basis in cron. How
I am teaching myself some Python and I have come across a problem which
In Python I have some data that looks like this: A = [ (-9,
I have made some code to display some content in Python/Kivy, and it seems
I have two files which have a list of sites in them. The master

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.