user11091815
user11091815

Reputation:

List in Python and sorting based on index with duplicate element

I want to sort the list2 by using list1 l

    ist1 = [7, 9, 12, 1, 4, 7]
    list2 = ['p','e','b','a','y','i']

the output should be

['a','y','p','i','e','b']

the p has the pair with 7 of smaller index

Upvotes: 1

Views: 35

Answers (1)

Alexander Lekontsev
Alexander Lekontsev

Reputation: 1012

[item[1] for item in sorted(zip(list1,list2))]

Upvotes: 2

Related Questions