0

In python I have:

    nameh.append([area, hitratio])
    nameh_sorted = sorted (nameh, key=lambda nameh: nameh[0])

I sorted the [area, hitratio] based on the alphabet of the name of the area. Then I want to zip the sorted "hitratio" with another list "u" into [u1, hitratio1], [u2, hitratio2]...but I don't know how to select the sorted hitratio in this case, the *nameh_sorted[1] is obviously wrong...

user = zip (u,*nameh_sorted[1])
user_sorted = sorted (user, key=lambda user: user[0])
x5, y5 = zip(*user_sorted) 

Can anyone help? Many thanks

1
  • 1
    You don't need to provide a key function in this case -- the default is to sort lexicographically, so the first element is the primary search key by default. Commented Jan 13, 2012 at 16:13

2 Answers 2

2
user = zip(u, (hitratio for area, hitratio in nameh_sorted))
Sign up to request clarification or add additional context in comments.

Comments

0

Try:

user = zip(u, [x[1] for x in nameh_sorted])

Is that what you want?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.