How to sort a list according to another list? Python -


so if have 1 list:

name = ['megan', 'harriet', 'henry', 'beth', 'george'] 

and have list each value represents names in right order

score_list = [9, 6, 5, 6, 10] 

so megan = 9 , beth = 6 (this dictionary way)

how sort name alphabetically keep score_list matching name? have done sorting numbers using bubble sort method not strings.

you can sort them @ same time tuples using zip. sorting name:

tuples = sorted(zip(name, score_list)) 

and then

name, score_list = [t[0] t in tuples], [t[1] t in tuples] 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -