;l.sort (reverse=true) >>>l>>>[4,3,2,1]
Example 3: Sort the second keyword
>>>l = [(' B ', 6), (' A ', 1), (' C ', 3), (' d ', 4)]>>>l.sort (Lambda x,y:cmp (x[1],y[1])) >>>L> >>[(' A ', 1), (' C ', 3), (' d ', 4), (' B ', 6)]
Example 4: Sort the second keyword
>>>l = [(' B ', 6), (' A ', 1), (' C ', 3), (' d ', 4)]>>>l.sort (Key=lambda x:x[1]) >>>l>>>[( ' A ', 1), (' C ', 3), (' d ', 4), (' B ', 6)]
Example 5: Sort the second keyword
>>>l = [(' B ', 2), (' A ', 1), (' C ', 3), (' d ', 4)]>
() does not return an object, changing the original list.Other examples of sort:Example 1: Forward Ordering
>>>l = [2,3,1,4] >>>l.sort () >>>l >>>[1,2,3,4]
Example 2: Reverse sorting
>>>l = [2,3,1,4] >>>l.sort (reverse=true) >>>l >>>[4,3,2,1]
Example 3: Sort the second keyword
>>>l = [(' B ', 6), (' A ', 1), (' C ', 3), (' d ', 4)] >>>l.sort (Lambda x,y:cmp (x[1],y[1])) >> >l >>>[(' A ', 1), (' C ', 3), (' d ', 4), (' B ', 6)]
Example 4: Sort the second keyword
>>>l = [(' B ', 6), ('
The following characters are the decrypted strings in irisskin2.If you are interested, you can study it.Put the text in notepad, delete "enter", and put it in a line
Dceqrmao1kvrmgl/fwhjgrnqug4ou/cisgw1 + DSU/iihskbzV4q ==Wt + C/hfeidcpzilyuomxd1thv3n1uiba35ddrzqz25o9pmmtaehiBzagpik5/qhdgf + sgm76qags5pzmm3da ==Khfnvp000ikyln91yvkvb3qek3zcfafernwgpyek6d05pzulawriWooeal69t/wpxognisrcewbx2w ==A6roupjzpjx4gsy6rn9myuxanrb2dufwkynpmqreqdbfd9nlng /J> > HW
. Site map can not only help stationmaster reasonable build inside chain, raise rank, also can give Spider crawl constructs a good channel, facilitate crawler to crawl to the whole website page, promote content to collect. BaiduSitemapThe earliest before is through the activity limited delivery, until last year the whole net open, this is a good thing for the grassroots webmaster. Official profile: Can speed up the content of the forum, and for high-quality data resources, can be found in Baidu
;l = [(' B ', 2), (' A ', 1), (' C ', 3), (' d ', 4)]
>>>import operator
>>>l.sort (Key=operator.itemgetter (1))
>>>l
>>>[(' A ', 1), (' B ', 2), (' C ', 3), (' d ', 4)]
Example 6: (DSU method: Decorate-sort-undercorate)
Copy Code code as follows:
>>>l = [(' B ', 2), (' A ', 1), (' C ', 3), (' d ', 4)]
>>>a = [(x[1],i,x) for i,x in Enumerate (L)] #i can confirm the stable sort
>>>a.sort ()
>>>l = [s[2] for s in A]
)
Returns an integer iteration that uses a parameter (stop) to range from 0 to stop-1, with two parameters (start and stop), and the range of iterations from start to Stop-1, and three parameters when using the value of the Iteration substring range from start to stop-1, interval step between each two values
Reversed (i)
Returns an iteration in which the iteration is reversed from the returned item in the Iteration child I
Sorted (I, key, reverse)
Returns the
Overview: share a function module that defines an output multi-list element.1. First create a folder for the templateEdit the nester.py file with the following content:def print_lol(the_list): forin the_list: if isinstance(each_item,list): print_lol(each_item) else: print(each_item)2. Create a file named "setup.py" in the new folderThe source code is as followsfromimport setupsetup( ‘nester‘, ‘1.0.0‘, py_moudles = [‘nester‘], ‘cs
key, the original order is preserved.Notice that two blue records remain in their original order, so (' Blue ', 1) must be before (' Blue ', 2).This awesome property allows you to sort through a series of sorts. For example, the student data is first sorted by grade ascending, and then by age descending, prioritizing age, and then sorting by grade:The timsort algorithm used by Python can effectively take advantage of the order that is already in the data set, so it can be efficiently ordered in
. sort (key = operator. itemgetter (1 ))>>> L>>> [('A', 1), ('B', 2), ('C', 3), ('D', 4)]Instance 6: (DSU method: Decorate-Sort-Undercorate)Copy codeThe Code is as follows:>>> L = [('B', 2), ('A', 1), ('C', 3), ('D', 4)]>>> A = [(x [1], I, x) for I, x in enumerate (L)] # I can confirm the stable sort>>> A. sort ()>>> L = [s [2] for s in A]>>> L>>> [('A', 1), ('B', 2), ('C', 3), ('D', 4)]In the preceding section, we use the List sorting method in Step
First, sort the list
The recommended sort method is to use the built-in sort () method, which is the fastest and is a stable sortCopy the Code code as follows:
>>> a = [1,9,3,7,2,0,5]
>>> A.sort ()
>>> Print a
[0, 1, 2, 3, 5, 7, 9]
>>> A.sort (reverse=true)
>>> Print a
[9, 7, 5, 3, 2, 1, 0]
>>> B = [' E ', ' A ', ' be ', ' ad ', ' dab ', ' DBC ']
>>> B.sort ()
>>> Print B
[' A ', ' ad ', ' Be ', ' dab ', ' DBC ', ' e ']
The ordering of the list follows the
; Import operator>>> L. sort (key = operator. itemgetter (1 ))>>> L>>> [('A', 1), ('B', 2), ('C', 3), ('D', 4)]
Instance 6: (DSU method: Decorate-Sort-Undercorate)
The code is as follows:
>>> L = [('B', 2), ('A', 1), ('C', 3), ('D', 4)]>>> A = [(x [1], I, x) for I, x in enumerate (L)] # I can confirm the stable sort>>> A. sort ()>>> L = [s [2] for s in A]>>> L>>> [('A', 1), ('B', 2), ('C', 3), ('D', 4)]
In the preceding section, we use the List sorti
This article mainly introduces the sorting methods of the dictionary (dict) and list (list) in Python. In summary, the built-in sort () method is preferred for sorting. For more information, see
I. sort the list
The recommended sorting method is the built-in sort () method, which is the fastest and stable.
The code is as follows:
>>> A = [1, 9, 3, 7, 2, 0, 5]>>> A. sort ()>>> Print[0, 1, 2, 3, 5, 7, 9]>>> A. sort (reverse = True)>>> Print[9, 7, 5, 3, 2, 1, 0]>>> B = ['e', 'A', 'be', 'AD', 'dab
Today, the efficiency is good, learned a lot of things, of which there are and check set, of course, I only learned a small part, but also need to do more to consolidate and practice.#include using namespacestd;classDisjointset {Private: int*father, *rank; Public: Disjointset (intsize) {Father=New int[size]; Rank=New int[size]; for(inti =0; i i) {Father[i]=i; Rank[i]=0; } } ~Disjointset () {Delete[] Father; Delete[] rank; } //Finding root Nodes intFind_set (intnode) { if(F
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.