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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:19:32+00:00 2026-06-01T07:19:32+00:00

I have a Version class that contains a version_number string, and can obtain a

  • 0

I have a Version class that contains a version_number string, and can obtain a sorted list of those strings like so:

sorted_versions = [v.version_number for v in self.version_set]
sorted_versions.sort(key=LooseVersion)

This works great!

sorted_versions: [u'1.6.3', u'1.7.0']

However, I would like to maintain a sorted list of the actual Version objects, not just their version_number properties, but I’m not sure how to accomplish this.

In my head, I would like to see something like this:

sorted_versions = self.version_set
sorted_versions.sort(key=LooseVersion, property=version_number)

Resulting in:

sorted_versions: [<Version: 1.6.3>, <Version: 1.7.0>]

  • 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-01T07:19:33+00:00Added an answer on June 1, 2026 at 7:19 am

    How about:

    sorted(self.version_set, key=lambda v:LooseVersion(v.version_number))
    

    Using sorted() here to avoid changing the original list which is what your ‘would like to see’ code would do if it worked.

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

Sidebar

Related Questions

I have a class library project that references the version 4.1 Microsoft.Practices.Common dll. I
If I have a class that contains only compile-time constants, for example, class A
I have a class that I serialize/deserialize using XmlSerializer . This class contains a
I have a class that contains a collection. I want to provided a method
I have a class that contains an NSDictionary and periodically, I have a thread
I have a class that represents some file data. The file contains some headers.
I have this Person class that is part of various other transactions like a
I have a decorated function (simplified version): class Memoize: def __init__(self, function): self.function =
Does Scala have a version of Rubys' each_slice from the Array class?
I have the SQL2008 version of SMO and although it uses this class internally

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.