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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:24:02+00:00 2026-05-30T11:24:02+00:00

I have an object roughly like so: class Hand(object): def __init__(self, finger_names, finger_lengths, nail_sizes):

  • 0

I have an object roughly like so:

class Hand(object):
    def __init__(self, finger_names, finger_lengths, nail_sizes):
        self.finger_names = finger_names
        self.finger_lengths = finger_lengths
        self.nail_sizes = nail_sizes

   def _sort_by_finger_lengths(self):
        ????

finger_names, finger_lengths and nail_sizes are all either equally long lists or empty (for example, if the person hasn’t measured their nail_sizes yet). The goal is to sort the attributes of the object by finger_lengths. So if you start with a Hand object where the lists are ordered by left-to-right names (pinky, ring, middle, pointer, thumb), you end up with a Hand object with all attributes sorted by finger_lengths.

Like so:

finger_names = [pinky, thumb, pointer, ring, middle]
finger_lengths = [6, 7, 12, 13, 15]
nail_sizes = []

EDITED TO ADD: Hand is just an example class. The real code has good reasons for having lists for each attribute.

  • 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-30T11:24:04+00:00Added an answer on May 30, 2026 at 11:24 am

    One simple approach is to do this:

    >>> finger_names, finger_lengths
    (('pointer', 'ring', 'pinky', 'middle', 'thumb'), (12, 13, 6, 15, 7))
    >>> s_tuples = sorted(zip(finger_names, finger_lengths), key=lambda x: x[1])
    >>> finger_names, finger_lengths = zip(*s_tuples)
    >>> finger_names, finger_lengths
    (('pinky', 'thumb', 'pointer', 'ring', 'middle'), (6, 7, 12, 13, 15))
    

    However, Nick is right that you should probably link these up in a data structure, instead of depending on their order to associate them.

    The above strategy (using key) still works in that case, but you don’t need to use zip(*s_tuples) to disassociate them.

    On the other hand, if you want to disassociate them, there’s a one-liner solution that I forgot about before.

    finger_lengths, finger_names = zip(*sorted(zip(finger_lengths, finger_names)))
    

    Or, if you want to sort in place, saving one copy operation:

    s_tuples = zip(finger_lengths, finger_names)
    s_tuples.sort()
    finger_lengths, finger_names = zip(*temp)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have objects which look very roughly like this: class object {
I have a c#-class that looks roughly like this: class ImageContainer { Image image;
I have something roughly like the following. Basically I need to access the class
I have just refactored a colleague's code that, roughly, looked like this... public class
I have an object of class F. I want to output the contents of
I would like to write an object generator for a templated RAII class --
I have several objects in C# that's roughly like this: A: { Id: 1,
OK so I'm looking a some code which looks roughly like this: void DoSomething(object
I have an SQL query (generated by LINQ to Entities) which is roughly like
I have some Scala code roughly analogous to this: object Foo { val thingA

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.