“Sort 2 list razem Python” Kod odpowiedzi

Sortuj dwie listy po jednym Pythonie

list1 = [3,2,4,1,1]
list2 = ['three', 'two', 'four', 'one', 'one2']
list1, list2 = zip(*sorted(zip(list1, list2)))
Comfortable Cockroach

sortować dwie listy, które wzajemnie się nawzajem

>>> list1 = [3,2,4,1, 1]
>>> list2 = ['three', 'two', 'four', 'one', 'one2']
>>> list1, list2 = zip(*sorted(zip(list1, list2)))
>>> list1
(1, 1, 2, 3, 4)
>>> list2 
('one', 'one2', 'two', 'three', 'four')
Tame Tamarin

Sort 2 list razem 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]
Panicky Platypus

Sort 2 list razem 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]
Panicky Platypus

Sort 2 list razem 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]
Panicky Platypus

Odpowiedzi podobne do “Sort 2 list razem Python”

Pytania podobne do “Sort 2 list razem Python”

Więcej pokrewnych odpowiedzi na “Sort 2 list razem Python” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu