Nested tuples in python list objects use the sort method to sort them

不言
Release: 2018-04-18 10:54:05
Original
2883 people have browsed it

The following article will share with you a sorting method based on sorting nested tuples in python list objects. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together

Nesting tuples in a list, when sorting, produces a copy of the original array. During the sorting process, first sort from small to large according to the first field. If the first field is the same, it will be sorted according to the second field, and so on. When letters are involved, it will be sorted in lexicographic order.

is as follows:

a = [(1, 'B'), (1, 'A'), (1, 'C'), (1, 'AC'), (2, 'B'), (2, 'A'), (1, 'ABC')] a a.sort() a
Copy after login

The output result is:

[(1, 'B'), (1, 'A'), (1, 'C'), (1, 'AC'), (2, 'B'), (2, 'A'), (1, 'ABC')] [(1, 'A'), (1, 'ABC'), (1, 'AC'), (1, 'B'), (1, 'C'), (2, 'A'), (2, 'B')]
Copy after login

Related recommendations:

Sort method when python list elements are tuples

The above is the detailed content of Nested tuples in python list objects use the sort method to sort them. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!