“Сортировка 2 списки вместе Python” Ответ

Сортировать два списка по одному питону

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

Сортировать два списка, которые возвращают друг друга

>>> 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

Сортировка 2 списки вместе 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

Сортировка 2 списки вместе 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

Сортировка 2 списки вместе 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

Ответы похожие на “Сортировка 2 списки вместе Python”

Вопросы похожие на “Сортировка 2 списки вместе Python”

Больше похожих ответов на “Сортировка 2 списки вместе Python” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования