Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Really easy python standoff

Tags:

python

I feel really dumb not to be able to solve something like this, but I'm point blank. I need to come up with a short and elegant way to do this, and for some reason I just can't!

The concept is very simple

I have a list with [4,3,5,2,1] and I have five individuals A, B, C, D, E

A=4 B=3 C=5 D=2 E=1

Now, I need to arrange them in ascending order based on their numbers so they become

['E', 'D', 'B', 'A', 'C']

I seriously don't get why I can't figure this one out D:

like image 636
Aayush Agrawal Avatar asked Feb 12 '26 22:02

Aayush Agrawal


1 Answers

order  =  [4, 3, 5, 2, 1]
people = "ABCDE"

result = [x[1] for x in sorted(zip(order, people))]
like image 98
kindall Avatar answered Feb 15 '26 12:02

kindall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!