Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sort 2 lists together python

D=[5,4,2,1,3]
C=["five","four","two","one","three"]
#Combine lists in tuples (5,"five"),(4,"four")...
zipped_lists=zip(D,C)
#Sorts by both values
sorted_pairs=sorted(zipped_lists)
#Unpacks and combines tuples like this (1,2,...) and ("one","two",...)
tuples=zip(*sorted_pairs)
#Lists now sorted
D,C=[list(tuple) for tuple in tuples]
 
PREVIOUS NEXT
Tagged: #sort #lists #python
ADD COMMENT
Topic
Name
8+6 =