[{"data":1,"prerenderedAt":2254},["ShallowReactive",2],{"doc-\u002Freference\u002Fpython-list-sort-method":3},{"id":4,"title":5,"body":6,"description":2247,"extension":2248,"meta":2249,"navigation":203,"path":2250,"seo":2251,"stem":2252,"__hash__":2253},"content\u002Freference\u002Fpython-list-sort-method.md","Python List sort() Method",{"type":7,"value":8,"toc":2213},"minimark",[9,19,26,32,37,116,125,132,137,155,158,217,220,248,256,260,297,300,316,319,384,386,413,417,422,478,480,506,511,572,574,599,602,609,613,616,686,688,723,726,788,790,823,829,906,908,940,947,954,960,963,976,979,1058,1060,1101,1104,1180,1182,1215,1220,1229,1237,1241,1250,1254,1262,1264,1336,1338,1375,1380,1394,1398,1403,1410,1413,1479,1481,1507,1514,1520,1524,1527,1569,1576,1583,1588,1591,1621,1627,1630,1680,1682,1744,1751,1756,1762,1831,1835,1838,1901,1903,1936,1941,1945,1948,2041,2044,2069,2075,2079,2086,2091,2100,2108,2112,2115,2138,2142,2144,2171,2174,2181,2184,2188,2209],[10,11,13,14,18],"h1",{"id":12},"python-list-sort-method","Python List ",[15,16,17],"code",{},"sort()"," Method",[20,21,22,25],"p",{},[15,23,24],{},"list.sort()"," is the built-in list method for sorting items in a list.",[20,27,28,29,31],{},"Use this page as a quick reference for what ",[15,30,17],{}," does, how its main arguments work, and the beginner mistakes to avoid.",[33,34,36],"h2",{"id":35},"quick-example","Quick example",[38,39,44],"pre",{"className":40,"code":41,"language":42,"meta":43,"style":43},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","numbers = [3, 1, 2]\nnumbers.sort()\nprint(numbers)  # [1, 2, 3]\n","python","",[15,45,46,81,97],{"__ignoreMap":43},[47,48,51,55,59,63,67,70,73,75,78],"span",{"class":49,"line":50},"line",1,[47,52,54],{"class":53},"su5hD","numbers ",[47,56,58],{"class":57},"smGrS","=",[47,60,62],{"class":61},"sP7_E"," [",[47,64,66],{"class":65},"srdBf","3",[47,68,69],{"class":61},",",[47,71,72],{"class":65}," 1",[47,74,69],{"class":61},[47,76,77],{"class":65}," 2",[47,79,80],{"class":61},"]\n",[47,82,84,87,90,94],{"class":49,"line":83},2,[47,85,86],{"class":53},"numbers",[47,88,89],{"class":61},".",[47,91,93],{"class":92},"slqww","sort",[47,95,96],{"class":61},"()\n",[47,98,100,104,107,109,112],{"class":49,"line":99},3,[47,101,103],{"class":102},"sptTA","print",[47,105,106],{"class":61},"(",[47,108,86],{"class":92},[47,110,111],{"class":61},")",[47,113,115],{"class":114},"sutJx","  # [1, 2, 3]\n",[20,117,118,119,121,122,89],{},"Use ",[15,120,24],{}," to sort a list in place. It changes the original list and returns ",[15,123,124],{},"None",[33,126,128,129,131],{"id":127},"what-listsort-does","What ",[15,130,24],{}," does",[20,133,134,136],{},[15,135,24],{},":",[138,139,140,144,147,152],"ul",{},[141,142,143],"li",{},"Sorts the items of a list in place",[141,145,146],{},"Changes the original list",[141,148,149,150],{},"Returns ",[15,151,124],{},[141,153,154],{},"Works for numbers and strings when items can be compared",[20,156,157],{},"This means the list itself is updated after you call the method.",[38,159,161],{"className":40,"code":160,"language":42,"meta":43,"style":43},"numbers = [5, 2, 9, 1]\nnumbers.sort()\n\nprint(numbers)\n",[15,162,163,189,199,205],{"__ignoreMap":43},[47,164,165,167,169,171,174,176,178,180,183,185,187],{"class":49,"line":50},[47,166,54],{"class":53},[47,168,58],{"class":57},[47,170,62],{"class":61},[47,172,173],{"class":65},"5",[47,175,69],{"class":61},[47,177,77],{"class":65},[47,179,69],{"class":61},[47,181,182],{"class":65}," 9",[47,184,69],{"class":61},[47,186,72],{"class":65},[47,188,80],{"class":61},[47,190,191,193,195,197],{"class":49,"line":83},[47,192,86],{"class":53},[47,194,89],{"class":61},[47,196,93],{"class":92},[47,198,96],{"class":61},[47,200,201],{"class":49,"line":99},[47,202,204],{"emptyLinePlaceholder":203},true,"\n",[47,206,208,210,212,214],{"class":49,"line":207},4,[47,209,103],{"class":102},[47,211,106],{"class":61},[47,213,86],{"class":92},[47,215,216],{"class":61},")\n",[20,218,219],{},"Output:",[38,221,223],{"className":40,"code":222,"language":42,"meta":43,"style":43},"[1, 2, 5, 9]\n",[15,224,225],{"__ignoreMap":43},[47,226,227,230,233,235,237,239,242,244,246],{"class":49,"line":50},[47,228,229],{"class":61},"[",[47,231,232],{"class":65},"1",[47,234,69],{"class":61},[47,236,77],{"class":65},[47,238,69],{"class":61},[47,240,241],{"class":65}," 5",[47,243,69],{"class":61},[47,245,182],{"class":65},[47,247,80],{"class":61},[20,249,250,251,89],{},"If you are still learning how lists work, see the ",[252,253,255],"a",{"href":254},"\u002Flearn\u002Fpython-lists-explained-beginner-guide\u002F","Python lists beginner guide",[33,257,259],{"id":258},"basic-syntax","Basic syntax",[38,261,263],{"className":40,"code":262,"language":42,"meta":43,"style":43},"my_list.sort(key=None, reverse=False)\n",[15,264,265],{"__ignoreMap":43},[47,266,267,270,272,274,276,280,282,285,287,290,292,295],{"class":49,"line":50},[47,268,269],{"class":53},"my_list",[47,271,89],{"class":61},[47,273,93],{"class":92},[47,275,106],{"class":61},[47,277,279],{"class":278},"s99_P","key",[47,281,58],{"class":57},[47,283,124],{"class":284},"s39Yj",[47,286,69],{"class":61},[47,288,289],{"class":278}," reverse",[47,291,58],{"class":57},[47,293,294],{"class":284},"False",[47,296,216],{"class":61},[20,298,299],{},"Main arguments:",[138,301,302,307,313],{},[141,303,304,306],{},[15,305,279],{}," lets you sort by a custom rule",[141,308,309,312],{},[15,310,311],{},"reverse=True"," sorts in descending order",[141,314,315],{},"If no arguments are given, sorting is ascending",[20,317,318],{},"Example:",[38,320,322],{"className":40,"code":321,"language":42,"meta":43,"style":43},"numbers = [4, 1, 7, 2]\nnumbers.sort(reverse=True)\n\nprint(numbers)\n",[15,323,324,350,370,374],{"__ignoreMap":43},[47,325,326,328,330,332,335,337,339,341,344,346,348],{"class":49,"line":50},[47,327,54],{"class":53},[47,329,58],{"class":57},[47,331,62],{"class":61},[47,333,334],{"class":65},"4",[47,336,69],{"class":61},[47,338,72],{"class":65},[47,340,69],{"class":61},[47,342,343],{"class":65}," 7",[47,345,69],{"class":61},[47,347,77],{"class":65},[47,349,80],{"class":61},[47,351,352,354,356,358,360,363,365,368],{"class":49,"line":83},[47,353,86],{"class":53},[47,355,89],{"class":61},[47,357,93],{"class":92},[47,359,106],{"class":61},[47,361,362],{"class":278},"reverse",[47,364,58],{"class":57},[47,366,367],{"class":284},"True",[47,369,216],{"class":61},[47,371,372],{"class":49,"line":99},[47,373,204],{"emptyLinePlaceholder":203},[47,375,376,378,380,382],{"class":49,"line":207},[47,377,103],{"class":102},[47,379,106],{"class":61},[47,381,86],{"class":92},[47,383,216],{"class":61},[20,385,219],{},[38,387,389],{"className":40,"code":388,"language":42,"meta":43,"style":43},"[7, 4, 2, 1]\n",[15,390,391],{"__ignoreMap":43},[47,392,393,395,398,400,403,405,407,409,411],{"class":49,"line":50},[47,394,229],{"class":61},[47,396,397],{"class":65},"7",[47,399,69],{"class":61},[47,401,402],{"class":65}," 4",[47,404,69],{"class":61},[47,406,77],{"class":65},[47,408,69],{"class":61},[47,410,72],{"class":65},[47,412,80],{"class":61},[33,414,416],{"id":415},"sort-numbers","Sort numbers",[20,418,118,419,421],{},[15,420,17],{}," when you want to sort numbers in ascending order.",[38,423,425],{"className":40,"code":424,"language":42,"meta":43,"style":43},"numbers = [10, 3, 8, 1]\nnumbers.sort()\n\nprint(numbers)\n",[15,426,427,454,464,468],{"__ignoreMap":43},[47,428,429,431,433,435,438,440,443,445,448,450,452],{"class":49,"line":50},[47,430,54],{"class":53},[47,432,58],{"class":57},[47,434,62],{"class":61},[47,436,437],{"class":65},"10",[47,439,69],{"class":61},[47,441,442],{"class":65}," 3",[47,444,69],{"class":61},[47,446,447],{"class":65}," 8",[47,449,69],{"class":61},[47,451,72],{"class":65},[47,453,80],{"class":61},[47,455,456,458,460,462],{"class":49,"line":83},[47,457,86],{"class":53},[47,459,89],{"class":61},[47,461,93],{"class":92},[47,463,96],{"class":61},[47,465,466],{"class":49,"line":99},[47,467,204],{"emptyLinePlaceholder":203},[47,469,470,472,474,476],{"class":49,"line":207},[47,471,103],{"class":102},[47,473,106],{"class":61},[47,475,86],{"class":92},[47,477,216],{"class":61},[20,479,219],{},[38,481,483],{"className":40,"code":482,"language":42,"meta":43,"style":43},"[1, 3, 8, 10]\n",[15,484,485],{"__ignoreMap":43},[47,486,487,489,491,493,495,497,499,501,504],{"class":49,"line":50},[47,488,229],{"class":61},[47,490,232],{"class":65},[47,492,69],{"class":61},[47,494,442],{"class":65},[47,496,69],{"class":61},[47,498,447],{"class":65},[47,500,69],{"class":61},[47,502,503],{"class":65}," 10",[47,505,80],{"class":61},[20,507,118,508,510],{},[15,509,311],{}," for descending order:",[38,512,514],{"className":40,"code":513,"language":42,"meta":43,"style":43},"numbers = [10, 3, 8, 1]\nnumbers.sort(reverse=True)\n\nprint(numbers)\n",[15,515,516,540,558,562],{"__ignoreMap":43},[47,517,518,520,522,524,526,528,530,532,534,536,538],{"class":49,"line":50},[47,519,54],{"class":53},[47,521,58],{"class":57},[47,523,62],{"class":61},[47,525,437],{"class":65},[47,527,69],{"class":61},[47,529,442],{"class":65},[47,531,69],{"class":61},[47,533,447],{"class":65},[47,535,69],{"class":61},[47,537,72],{"class":65},[47,539,80],{"class":61},[47,541,542,544,546,548,550,552,554,556],{"class":49,"line":83},[47,543,86],{"class":53},[47,545,89],{"class":61},[47,547,93],{"class":92},[47,549,106],{"class":61},[47,551,362],{"class":278},[47,553,58],{"class":57},[47,555,367],{"class":284},[47,557,216],{"class":61},[47,559,560],{"class":49,"line":99},[47,561,204],{"emptyLinePlaceholder":203},[47,563,564,566,568,570],{"class":49,"line":207},[47,565,103],{"class":102},[47,567,106],{"class":61},[47,569,86],{"class":92},[47,571,216],{"class":61},[20,573,219],{},[38,575,577],{"className":40,"code":576,"language":42,"meta":43,"style":43},"[10, 8, 3, 1]\n",[15,578,579],{"__ignoreMap":43},[47,580,581,583,585,587,589,591,593,595,597],{"class":49,"line":50},[47,582,229],{"class":61},[47,584,437],{"class":65},[47,586,69],{"class":61},[47,588,447],{"class":65},[47,590,69],{"class":61},[47,592,442],{"class":65},[47,594,69],{"class":61},[47,596,72],{"class":65},[47,598,80],{"class":61},[20,600,601],{},"The important thing to remember is that the original list is updated after the method call.",[20,603,604,605,89],{},"For a task-focused guide, read ",[252,606,608],{"href":607},"\u002Fhow-to\u002Fhow-to-sort-a-list-in-python\u002F","how to sort a list in Python",[33,610,612],{"id":611},"sort-strings","Sort strings",[20,614,615],{},"Strings are sorted alphabetically by default.",[38,617,619],{"className":40,"code":618,"language":42,"meta":43,"style":43},"words = [\"banana\", \"apple\", \"cherry\"]\nwords.sort()\n\nprint(words)\n",[15,620,621,661,672,676],{"__ignoreMap":43},[47,622,623,626,628,630,634,638,640,642,645,648,650,652,654,657,659],{"class":49,"line":50},[47,624,625],{"class":53},"words ",[47,627,58],{"class":57},[47,629,62],{"class":61},[47,631,633],{"class":632},"sjJ54","\"",[47,635,637],{"class":636},"s_sjI","banana",[47,639,633],{"class":632},[47,641,69],{"class":61},[47,643,644],{"class":632}," \"",[47,646,647],{"class":636},"apple",[47,649,633],{"class":632},[47,651,69],{"class":61},[47,653,644],{"class":632},[47,655,656],{"class":636},"cherry",[47,658,633],{"class":632},[47,660,80],{"class":61},[47,662,663,666,668,670],{"class":49,"line":83},[47,664,665],{"class":53},"words",[47,667,89],{"class":61},[47,669,93],{"class":92},[47,671,96],{"class":61},[47,673,674],{"class":49,"line":99},[47,675,204],{"emptyLinePlaceholder":203},[47,677,678,680,682,684],{"class":49,"line":207},[47,679,103],{"class":102},[47,681,106],{"class":61},[47,683,665],{"class":92},[47,685,216],{"class":61},[20,687,219],{},[38,689,691],{"className":40,"code":690,"language":42,"meta":43,"style":43},"['apple', 'banana', 'cherry']\n",[15,692,693],{"__ignoreMap":43},[47,694,695,697,700,702,704,706,709,711,713,715,717,719,721],{"class":49,"line":50},[47,696,229],{"class":61},[47,698,699],{"class":632},"'",[47,701,647],{"class":636},[47,703,699],{"class":632},[47,705,69],{"class":61},[47,707,708],{"class":632}," '",[47,710,637],{"class":636},[47,712,699],{"class":632},[47,714,69],{"class":61},[47,716,708],{"class":632},[47,718,656],{"class":636},[47,720,699],{"class":632},[47,722,80],{"class":61},[20,724,725],{},"Uppercase and lowercase letters affect the result:",[38,727,729],{"className":40,"code":728,"language":42,"meta":43,"style":43},"words = [\"banana\", \"Apple\", \"cherry\"]\nwords.sort()\n\nprint(words)\n",[15,730,731,764,774,778],{"__ignoreMap":43},[47,732,733,735,737,739,741,743,745,747,749,752,754,756,758,760,762],{"class":49,"line":50},[47,734,625],{"class":53},[47,736,58],{"class":57},[47,738,62],{"class":61},[47,740,633],{"class":632},[47,742,637],{"class":636},[47,744,633],{"class":632},[47,746,69],{"class":61},[47,748,644],{"class":632},[47,750,751],{"class":636},"Apple",[47,753,633],{"class":632},[47,755,69],{"class":61},[47,757,644],{"class":632},[47,759,656],{"class":636},[47,761,633],{"class":632},[47,763,80],{"class":61},[47,765,766,768,770,772],{"class":49,"line":83},[47,767,665],{"class":53},[47,769,89],{"class":61},[47,771,93],{"class":92},[47,773,96],{"class":61},[47,775,776],{"class":49,"line":99},[47,777,204],{"emptyLinePlaceholder":203},[47,779,780,782,784,786],{"class":49,"line":207},[47,781,103],{"class":102},[47,783,106],{"class":61},[47,785,665],{"class":92},[47,787,216],{"class":61},[20,789,219],{},[38,791,793],{"className":40,"code":792,"language":42,"meta":43,"style":43},"['Apple', 'banana', 'cherry']\n",[15,794,795],{"__ignoreMap":43},[47,796,797,799,801,803,805,807,809,811,813,815,817,819,821],{"class":49,"line":50},[47,798,229],{"class":61},[47,800,699],{"class":632},[47,802,751],{"class":636},[47,804,699],{"class":632},[47,806,69],{"class":61},[47,808,708],{"class":632},[47,810,637],{"class":636},[47,812,699],{"class":632},[47,814,69],{"class":61},[47,816,708],{"class":632},[47,818,656],{"class":636},[47,820,699],{"class":632},[47,822,80],{"class":61},[20,824,825,826,136],{},"If you want case-insensitive sorting, use ",[15,827,828],{},"key=str.lower",[38,830,832],{"className":40,"code":831,"language":42,"meta":43,"style":43},"words = [\"banana\", \"Apple\", \"cherry\"]\nwords.sort(key=str.lower)\n\nprint(words)\n",[15,833,834,866,892,896],{"__ignoreMap":43},[47,835,836,838,840,842,844,846,848,850,852,854,856,858,860,862,864],{"class":49,"line":50},[47,837,625],{"class":53},[47,839,58],{"class":57},[47,841,62],{"class":61},[47,843,633],{"class":632},[47,845,637],{"class":636},[47,847,633],{"class":632},[47,849,69],{"class":61},[47,851,644],{"class":632},[47,853,751],{"class":636},[47,855,633],{"class":632},[47,857,69],{"class":61},[47,859,644],{"class":632},[47,861,656],{"class":636},[47,863,633],{"class":632},[47,865,80],{"class":61},[47,867,868,870,872,874,876,878,880,884,886,890],{"class":49,"line":83},[47,869,665],{"class":53},[47,871,89],{"class":61},[47,873,93],{"class":92},[47,875,106],{"class":61},[47,877,279],{"class":278},[47,879,58],{"class":57},[47,881,883],{"class":882},"sZMiF","str",[47,885,89],{"class":61},[47,887,889],{"class":888},"skxfh","lower",[47,891,216],{"class":61},[47,893,894],{"class":49,"line":99},[47,895,204],{"emptyLinePlaceholder":203},[47,897,898,900,902,904],{"class":49,"line":207},[47,899,103],{"class":102},[47,901,106],{"class":61},[47,903,665],{"class":92},[47,905,216],{"class":61},[20,907,219],{},[38,909,910],{"className":40,"code":792,"language":42,"meta":43,"style":43},[15,911,912],{"__ignoreMap":43},[47,913,914,916,918,920,922,924,926,928,930,932,934,936,938],{"class":49,"line":50},[47,915,229],{"class":61},[47,917,699],{"class":632},[47,919,751],{"class":636},[47,921,699],{"class":632},[47,923,69],{"class":61},[47,925,708],{"class":632},[47,927,637],{"class":636},[47,929,699],{"class":632},[47,931,69],{"class":61},[47,933,708],{"class":632},[47,935,656],{"class":636},[47,937,699],{"class":632},[47,939,80],{"class":61},[20,941,942,943,946],{},"The original spelling stays the same. Python only uses ",[15,944,945],{},"str.lower"," as the sorting rule.",[33,948,950,951,953],{"id":949},"using-the-key-argument","Using the ",[15,952,279],{}," argument",[20,955,956,957,959],{},"The ",[15,958,279],{}," argument changes how each item is compared.",[20,961,962],{},"Common examples:",[138,964,965,971],{},[141,966,967,970],{},[15,968,969],{},"len"," to sort by length",[141,972,973,975],{},[15,974,945],{}," to sort strings without case problems",[20,977,978],{},"Sort words by length:",[38,980,982],{"className":40,"code":981,"language":42,"meta":43,"style":43},"words = [\"pear\", \"banana\", \"fig\", \"apple\"]\nwords.sort(key=len)\n\nprint(words)\n",[15,983,984,1026,1044,1048],{"__ignoreMap":43},[47,985,986,988,990,992,994,997,999,1001,1003,1005,1007,1009,1011,1014,1016,1018,1020,1022,1024],{"class":49,"line":50},[47,987,625],{"class":53},[47,989,58],{"class":57},[47,991,62],{"class":61},[47,993,633],{"class":632},[47,995,996],{"class":636},"pear",[47,998,633],{"class":632},[47,1000,69],{"class":61},[47,1002,644],{"class":632},[47,1004,637],{"class":636},[47,1006,633],{"class":632},[47,1008,69],{"class":61},[47,1010,644],{"class":632},[47,1012,1013],{"class":636},"fig",[47,1015,633],{"class":632},[47,1017,69],{"class":61},[47,1019,644],{"class":632},[47,1021,647],{"class":636},[47,1023,633],{"class":632},[47,1025,80],{"class":61},[47,1027,1028,1030,1032,1034,1036,1038,1040,1042],{"class":49,"line":83},[47,1029,665],{"class":53},[47,1031,89],{"class":61},[47,1033,93],{"class":92},[47,1035,106],{"class":61},[47,1037,279],{"class":278},[47,1039,58],{"class":57},[47,1041,969],{"class":102},[47,1043,216],{"class":61},[47,1045,1046],{"class":49,"line":99},[47,1047,204],{"emptyLinePlaceholder":203},[47,1049,1050,1052,1054,1056],{"class":49,"line":207},[47,1051,103],{"class":102},[47,1053,106],{"class":61},[47,1055,665],{"class":92},[47,1057,216],{"class":61},[20,1059,219],{},[38,1061,1063],{"className":40,"code":1062,"language":42,"meta":43,"style":43},"['fig', 'pear', 'apple', 'banana']\n",[15,1064,1065],{"__ignoreMap":43},[47,1066,1067,1069,1071,1073,1075,1077,1079,1081,1083,1085,1087,1089,1091,1093,1095,1097,1099],{"class":49,"line":50},[47,1068,229],{"class":61},[47,1070,699],{"class":632},[47,1072,1013],{"class":636},[47,1074,699],{"class":632},[47,1076,69],{"class":61},[47,1078,708],{"class":632},[47,1080,996],{"class":636},[47,1082,699],{"class":632},[47,1084,69],{"class":61},[47,1086,708],{"class":632},[47,1088,647],{"class":636},[47,1090,699],{"class":632},[47,1092,69],{"class":61},[47,1094,708],{"class":632},[47,1096,637],{"class":636},[47,1098,699],{"class":632},[47,1100,80],{"class":61},[20,1102,1103],{},"Sort strings without case sensitivity:",[38,1105,1107],{"className":40,"code":1106,"language":42,"meta":43,"style":43},"words = [\"Bob\", \"alice\", \"Carol\"]\nwords.sort(key=str.lower)\n\nprint(words)\n",[15,1108,1109,1144,1166,1170],{"__ignoreMap":43},[47,1110,1111,1113,1115,1117,1119,1122,1124,1126,1128,1131,1133,1135,1137,1140,1142],{"class":49,"line":50},[47,1112,625],{"class":53},[47,1114,58],{"class":57},[47,1116,62],{"class":61},[47,1118,633],{"class":632},[47,1120,1121],{"class":636},"Bob",[47,1123,633],{"class":632},[47,1125,69],{"class":61},[47,1127,644],{"class":632},[47,1129,1130],{"class":636},"alice",[47,1132,633],{"class":632},[47,1134,69],{"class":61},[47,1136,644],{"class":632},[47,1138,1139],{"class":636},"Carol",[47,1141,633],{"class":632},[47,1143,80],{"class":61},[47,1145,1146,1148,1150,1152,1154,1156,1158,1160,1162,1164],{"class":49,"line":83},[47,1147,665],{"class":53},[47,1149,89],{"class":61},[47,1151,93],{"class":92},[47,1153,106],{"class":61},[47,1155,279],{"class":278},[47,1157,58],{"class":57},[47,1159,883],{"class":882},[47,1161,89],{"class":61},[47,1163,889],{"class":888},[47,1165,216],{"class":61},[47,1167,1168],{"class":49,"line":99},[47,1169,204],{"emptyLinePlaceholder":203},[47,1171,1172,1174,1176,1178],{"class":49,"line":207},[47,1173,103],{"class":102},[47,1175,106],{"class":61},[47,1177,665],{"class":92},[47,1179,216],{"class":61},[20,1181,219],{},[38,1183,1185],{"className":40,"code":1184,"language":42,"meta":43,"style":43},"['alice', 'Bob', 'Carol']\n",[15,1186,1187],{"__ignoreMap":43},[47,1188,1189,1191,1193,1195,1197,1199,1201,1203,1205,1207,1209,1211,1213],{"class":49,"line":50},[47,1190,229],{"class":61},[47,1192,699],{"class":632},[47,1194,1130],{"class":636},[47,1196,699],{"class":632},[47,1198,69],{"class":61},[47,1200,708],{"class":632},[47,1202,1121],{"class":636},[47,1204,699],{"class":632},[47,1206,69],{"class":61},[47,1208,708],{"class":632},[47,1210,1139],{"class":636},[47,1212,699],{"class":632},[47,1214,80],{"class":61},[20,1216,956,1217,1219],{},[15,1218,279],{}," argument is especially useful when the default alphabetical or numeric order is not what you want.",[33,1221,1223,1225,1226],{"id":1222},"listsort-vs-sorted",[15,1224,24],{}," vs ",[15,1227,1228],{},"sorted()",[20,1230,1231,1233,1234,1236],{},[15,1232,24],{}," and ",[15,1235,1228],{}," both sort data, but they work differently.",[20,1238,1239,136],{},[15,1240,24],{},[138,1242,1243,1246],{},[141,1244,1245],{},"Changes the existing list",[141,1247,149,1248],{},[15,1249,124],{},[20,1251,1252,136],{},[15,1253,1228],{},[138,1255,1256,1259],{},[141,1257,1258],{},"Returns a new sorted list",[141,1260,1261],{},"Leaves the original unchanged",[20,1263,318],{},[38,1265,1267],{"className":40,"code":1266,"language":42,"meta":43,"style":43},"numbers = [3, 1, 2]\n\nnew_list = sorted(numbers)\n\nprint(numbers)\nprint(new_list)\n",[15,1268,1269,1289,1293,1309,1313,1324],{"__ignoreMap":43},[47,1270,1271,1273,1275,1277,1279,1281,1283,1285,1287],{"class":49,"line":50},[47,1272,54],{"class":53},[47,1274,58],{"class":57},[47,1276,62],{"class":61},[47,1278,66],{"class":65},[47,1280,69],{"class":61},[47,1282,72],{"class":65},[47,1284,69],{"class":61},[47,1286,77],{"class":65},[47,1288,80],{"class":61},[47,1290,1291],{"class":49,"line":83},[47,1292,204],{"emptyLinePlaceholder":203},[47,1294,1295,1298,1300,1303,1305,1307],{"class":49,"line":99},[47,1296,1297],{"class":53},"new_list ",[47,1299,58],{"class":57},[47,1301,1302],{"class":102}," sorted",[47,1304,106],{"class":61},[47,1306,86],{"class":92},[47,1308,216],{"class":61},[47,1310,1311],{"class":49,"line":207},[47,1312,204],{"emptyLinePlaceholder":203},[47,1314,1316,1318,1320,1322],{"class":49,"line":1315},5,[47,1317,103],{"class":102},[47,1319,106],{"class":61},[47,1321,86],{"class":92},[47,1323,216],{"class":61},[47,1325,1327,1329,1331,1334],{"class":49,"line":1326},6,[47,1328,103],{"class":102},[47,1330,106],{"class":61},[47,1332,1333],{"class":92},"new_list",[47,1335,216],{"class":61},[20,1337,219],{},[38,1339,1341],{"className":40,"code":1340,"language":42,"meta":43,"style":43},"[3, 1, 2]\n[1, 2, 3]\n",[15,1342,1343,1359],{"__ignoreMap":43},[47,1344,1345,1347,1349,1351,1353,1355,1357],{"class":49,"line":50},[47,1346,229],{"class":61},[47,1348,66],{"class":65},[47,1350,69],{"class":61},[47,1352,72],{"class":65},[47,1354,69],{"class":61},[47,1356,77],{"class":65},[47,1358,80],{"class":61},[47,1360,1361,1363,1365,1367,1369,1371,1373],{"class":49,"line":83},[47,1362,229],{"class":61},[47,1364,232],{"class":65},[47,1366,69],{"class":61},[47,1368,77],{"class":65},[47,1370,69],{"class":61},[47,1372,442],{"class":65},[47,1374,80],{"class":61},[20,1376,118,1377,1379],{},[15,1378,1228],{}," when you want to keep the original list unchanged.",[20,1381,1382,1383,1233,1390,89],{},"You can learn more in ",[252,1384,1386,1387,1389],{"href":1385},"\u002Freference\u002Fpython-sorted-function-explained\u002F","Python ",[15,1388,1228],{}," explained",[252,1391,1393],{"href":1392},"\u002Freference\u002Fpython-sorted-vs-list.sort-explained","sorted() vs list.sort() explained",[33,1395,1397],{"id":1396},"common-mistakes","Common mistakes",[20,1399,1400,1401,89],{},"Here are the most common beginner mistakes with ",[15,1402,24],{},[1404,1405,1407,1408],"h3",{"id":1406},"assigning-the-result-of-sort","Assigning the result of ",[15,1409,17],{},[20,1411,1412],{},"This is a very common mistake:",[38,1414,1416],{"className":40,"code":1415,"language":42,"meta":43,"style":43},"numbers = [3, 1, 2]\nresult = numbers.sort()\n\nprint(result)\nprint(numbers)\n",[15,1417,1418,1438,1454,1458,1469],{"__ignoreMap":43},[47,1419,1420,1422,1424,1426,1428,1430,1432,1434,1436],{"class":49,"line":50},[47,1421,54],{"class":53},[47,1423,58],{"class":57},[47,1425,62],{"class":61},[47,1427,66],{"class":65},[47,1429,69],{"class":61},[47,1431,72],{"class":65},[47,1433,69],{"class":61},[47,1435,77],{"class":65},[47,1437,80],{"class":61},[47,1439,1440,1443,1445,1448,1450,1452],{"class":49,"line":83},[47,1441,1442],{"class":53},"result ",[47,1444,58],{"class":57},[47,1446,1447],{"class":53}," numbers",[47,1449,89],{"class":61},[47,1451,93],{"class":92},[47,1453,96],{"class":61},[47,1455,1456],{"class":49,"line":99},[47,1457,204],{"emptyLinePlaceholder":203},[47,1459,1460,1462,1464,1467],{"class":49,"line":207},[47,1461,103],{"class":102},[47,1463,106],{"class":61},[47,1465,1466],{"class":92},"result",[47,1468,216],{"class":61},[47,1470,1471,1473,1475,1477],{"class":49,"line":1315},[47,1472,103],{"class":102},[47,1474,106],{"class":61},[47,1476,86],{"class":92},[47,1478,216],{"class":61},[20,1480,219],{},[38,1482,1484],{"className":40,"code":1483,"language":42,"meta":43,"style":43},"None\n[1, 2, 3]\n",[15,1485,1486,1491],{"__ignoreMap":43},[47,1487,1488],{"class":49,"line":50},[47,1489,1490],{"class":284},"None\n",[47,1492,1493,1495,1497,1499,1501,1503,1505],{"class":49,"line":83},[47,1494,229],{"class":61},[47,1496,232],{"class":65},[47,1498,69],{"class":61},[47,1500,77],{"class":65},[47,1502,69],{"class":61},[47,1504,442],{"class":65},[47,1506,80],{"class":61},[20,1508,1509,1511,1512,89],{},[15,1510,17],{}," does not return the sorted list. It returns ",[15,1513,124],{},[20,1515,1516,1517,1519],{},"If you want a new list, use ",[15,1518,1228],{}," instead.",[1404,1521,1523],{"id":1522},"sorting-mixed-types","Sorting mixed types",[20,1525,1526],{},"Python cannot always compare different types directly.",[38,1528,1530],{"className":40,"code":1529,"language":42,"meta":43,"style":43},"items = [1, \"two\", 3]\nitems.sort()\n",[15,1531,1532,1558],{"__ignoreMap":43},[47,1533,1534,1537,1539,1541,1543,1545,1547,1550,1552,1554,1556],{"class":49,"line":50},[47,1535,1536],{"class":53},"items ",[47,1538,58],{"class":57},[47,1540,62],{"class":61},[47,1542,232],{"class":65},[47,1544,69],{"class":61},[47,1546,644],{"class":632},[47,1548,1549],{"class":636},"two",[47,1551,633],{"class":632},[47,1553,69],{"class":61},[47,1555,442],{"class":65},[47,1557,80],{"class":61},[47,1559,1560,1563,1565,1567],{"class":49,"line":83},[47,1561,1562],{"class":53},"items",[47,1564,89],{"class":61},[47,1566,93],{"class":92},[47,1568,96],{"class":61},[20,1570,1571,1572,1575],{},"This raises a ",[15,1573,1574],{},"TypeError"," because Python cannot sort integers and strings together by default.",[1404,1577,1579,1580,1582],{"id":1578},"forgetting-that-sort-only-works-on-lists","Forgetting that ",[15,1581,17],{}," only works on lists",[20,1584,1585,1587],{},[15,1586,17],{}," is a list method. It does not work directly on tuples or strings.",[20,1589,1590],{},"Wrong:",[38,1592,1594],{"className":40,"code":1593,"language":42,"meta":43,"style":43},"text = \"python\"\ntext.sort()\n",[15,1595,1596,1610],{"__ignoreMap":43},[47,1597,1598,1601,1603,1605,1607],{"class":49,"line":50},[47,1599,1600],{"class":53},"text ",[47,1602,58],{"class":57},[47,1604,644],{"class":632},[47,1606,42],{"class":636},[47,1608,1609],{"class":632},"\"\n",[47,1611,1612,1615,1617,1619],{"class":49,"line":83},[47,1613,1614],{"class":53},"text",[47,1616,89],{"class":61},[47,1618,93],{"class":92},[47,1620,96],{"class":61},[20,1622,1623,1624,1626],{},"Strings do not have a ",[15,1625,17],{}," method.",[20,1628,1629],{},"If needed, convert the data first:",[38,1631,1633],{"className":40,"code":1632,"language":42,"meta":43,"style":43},"letters = list(\"python\")\nletters.sort()\n\nprint(letters)\n",[15,1634,1635,1655,1666,1670],{"__ignoreMap":43},[47,1636,1637,1640,1642,1645,1647,1649,1651,1653],{"class":49,"line":50},[47,1638,1639],{"class":53},"letters ",[47,1641,58],{"class":57},[47,1643,1644],{"class":882}," list",[47,1646,106],{"class":61},[47,1648,633],{"class":632},[47,1650,42],{"class":636},[47,1652,633],{"class":632},[47,1654,216],{"class":61},[47,1656,1657,1660,1662,1664],{"class":49,"line":83},[47,1658,1659],{"class":53},"letters",[47,1661,89],{"class":61},[47,1663,93],{"class":92},[47,1665,96],{"class":61},[47,1667,1668],{"class":49,"line":99},[47,1669,204],{"emptyLinePlaceholder":203},[47,1671,1672,1674,1676,1678],{"class":49,"line":207},[47,1673,103],{"class":102},[47,1675,106],{"class":61},[47,1677,1659],{"class":92},[47,1679,216],{"class":61},[20,1681,219],{},[38,1683,1685],{"className":40,"code":1684,"language":42,"meta":43,"style":43},"['h', 'n', 'o', 'p', 't', 'y']\n",[15,1686,1687],{"__ignoreMap":43},[47,1688,1689,1691,1693,1696,1698,1700,1702,1705,1707,1709,1711,1714,1716,1718,1720,1722,1724,1726,1728,1731,1733,1735,1737,1740,1742],{"class":49,"line":50},[47,1690,229],{"class":61},[47,1692,699],{"class":632},[47,1694,1695],{"class":636},"h",[47,1697,699],{"class":632},[47,1699,69],{"class":61},[47,1701,708],{"class":632},[47,1703,1704],{"class":636},"n",[47,1706,699],{"class":632},[47,1708,69],{"class":61},[47,1710,708],{"class":632},[47,1712,1713],{"class":636},"o",[47,1715,699],{"class":632},[47,1717,69],{"class":61},[47,1719,708],{"class":632},[47,1721,20],{"class":636},[47,1723,699],{"class":632},[47,1725,69],{"class":61},[47,1727,708],{"class":632},[47,1729,1730],{"class":636},"t",[47,1732,699],{"class":632},[47,1734,69],{"class":61},[47,1736,708],{"class":632},[47,1738,1739],{"class":636},"y",[47,1741,699],{"class":632},[47,1743,80],{"class":61},[1404,1745,1747,1748,1750],{"id":1746},"not-using-key-when-custom-sorting-is-needed","Not using ",[15,1749,279],{}," when custom sorting is needed",[20,1752,1753,1754,89],{},"If the default order is not correct for your problem, you may need ",[15,1755,279],{},[20,1757,1758,1759,1761],{},"For example, if you want to sort words by length, plain ",[15,1760,17],{}," will not do that:",[38,1763,1765],{"className":40,"code":1764,"language":42,"meta":43,"style":43},"words = [\"banana\", \"fig\", \"apple\"]\nwords.sort(key=len)\n\nprint(words)\n",[15,1766,1767,1799,1817,1821],{"__ignoreMap":43},[47,1768,1769,1771,1773,1775,1777,1779,1781,1783,1785,1787,1789,1791,1793,1795,1797],{"class":49,"line":50},[47,1770,625],{"class":53},[47,1772,58],{"class":57},[47,1774,62],{"class":61},[47,1776,633],{"class":632},[47,1778,637],{"class":636},[47,1780,633],{"class":632},[47,1782,69],{"class":61},[47,1784,644],{"class":632},[47,1786,1013],{"class":636},[47,1788,633],{"class":632},[47,1790,69],{"class":61},[47,1792,644],{"class":632},[47,1794,647],{"class":636},[47,1796,633],{"class":632},[47,1798,80],{"class":61},[47,1800,1801,1803,1805,1807,1809,1811,1813,1815],{"class":49,"line":83},[47,1802,665],{"class":53},[47,1804,89],{"class":61},[47,1806,93],{"class":92},[47,1808,106],{"class":61},[47,1810,279],{"class":278},[47,1812,58],{"class":57},[47,1814,969],{"class":102},[47,1816,216],{"class":61},[47,1818,1819],{"class":49,"line":99},[47,1820,204],{"emptyLinePlaceholder":203},[47,1822,1823,1825,1827,1829],{"class":49,"line":207},[47,1824,103],{"class":102},[47,1826,106],{"class":61},[47,1828,665],{"class":92},[47,1830,216],{"class":61},[1404,1832,1834],{"id":1833},"unexpected-string-order-because-of-uppercase-letters","Unexpected string order because of uppercase letters",[20,1836,1837],{},"This often surprises beginners:",[38,1839,1841],{"className":40,"code":1840,"language":42,"meta":43,"style":43},"words = [\"zebra\", \"Apple\", \"monkey\"]\nwords.sort()\n\nprint(words)\n",[15,1842,1843,1877,1887,1891],{"__ignoreMap":43},[47,1844,1845,1847,1849,1851,1853,1856,1858,1860,1862,1864,1866,1868,1870,1873,1875],{"class":49,"line":50},[47,1846,625],{"class":53},[47,1848,58],{"class":57},[47,1850,62],{"class":61},[47,1852,633],{"class":632},[47,1854,1855],{"class":636},"zebra",[47,1857,633],{"class":632},[47,1859,69],{"class":61},[47,1861,644],{"class":632},[47,1863,751],{"class":636},[47,1865,633],{"class":632},[47,1867,69],{"class":61},[47,1869,644],{"class":632},[47,1871,1872],{"class":636},"monkey",[47,1874,633],{"class":632},[47,1876,80],{"class":61},[47,1878,1879,1881,1883,1885],{"class":49,"line":83},[47,1880,665],{"class":53},[47,1882,89],{"class":61},[47,1884,93],{"class":92},[47,1886,96],{"class":61},[47,1888,1889],{"class":49,"line":99},[47,1890,204],{"emptyLinePlaceholder":203},[47,1892,1893,1895,1897,1899],{"class":49,"line":207},[47,1894,103],{"class":102},[47,1896,106],{"class":61},[47,1898,665],{"class":92},[47,1900,216],{"class":61},[20,1902,219],{},[38,1904,1906],{"className":40,"code":1905,"language":42,"meta":43,"style":43},"['Apple', 'monkey', 'zebra']\n",[15,1907,1908],{"__ignoreMap":43},[47,1909,1910,1912,1914,1916,1918,1920,1922,1924,1926,1928,1930,1932,1934],{"class":49,"line":50},[47,1911,229],{"class":61},[47,1913,699],{"class":632},[47,1915,751],{"class":636},[47,1917,699],{"class":632},[47,1919,69],{"class":61},[47,1921,708],{"class":632},[47,1923,1872],{"class":636},[47,1925,699],{"class":632},[47,1927,69],{"class":61},[47,1929,708],{"class":632},[47,1931,1855],{"class":636},[47,1933,699],{"class":632},[47,1935,80],{"class":61},[20,1937,118,1938,1940],{},[15,1939,828],{}," if you want case-insensitive sorting.",[1404,1942,1944],{"id":1943},"useful-debugging-checks","Useful debugging checks",[20,1946,1947],{},"If sorting is not working as expected, these quick checks can help:",[38,1949,1951],{"className":40,"code":1950,"language":42,"meta":43,"style":43},"print(my_list)\nprint(type(my_list))\nprint(my_list.sort())\nprint(sorted(my_list))\nprint([type(item) for item in my_list])\n",[15,1952,1953,1963,1979,1994,2009],{"__ignoreMap":43},[47,1954,1955,1957,1959,1961],{"class":49,"line":50},[47,1956,103],{"class":102},[47,1958,106],{"class":61},[47,1960,269],{"class":92},[47,1962,216],{"class":61},[47,1964,1965,1967,1969,1972,1974,1976],{"class":49,"line":83},[47,1966,103],{"class":102},[47,1968,106],{"class":61},[47,1970,1971],{"class":882},"type",[47,1973,106],{"class":61},[47,1975,269],{"class":92},[47,1977,1978],{"class":61},"))\n",[47,1980,1981,1983,1985,1987,1989,1991],{"class":49,"line":99},[47,1982,103],{"class":102},[47,1984,106],{"class":61},[47,1986,269],{"class":92},[47,1988,89],{"class":61},[47,1990,93],{"class":92},[47,1992,1993],{"class":61},"())\n",[47,1995,1996,1998,2000,2003,2005,2007],{"class":49,"line":207},[47,1997,103],{"class":102},[47,1999,106],{"class":61},[47,2001,2002],{"class":102},"sorted",[47,2004,106],{"class":61},[47,2006,269],{"class":92},[47,2008,1978],{"class":61},[47,2010,2011,2013,2016,2018,2020,2023,2025,2029,2032,2035,2038],{"class":49,"line":1315},[47,2012,103],{"class":102},[47,2014,2015],{"class":61},"([",[47,2017,1971],{"class":882},[47,2019,106],{"class":61},[47,2021,2022],{"class":92},"item",[47,2024,111],{"class":61},[47,2026,2028],{"class":2027},"sVHd0"," for",[47,2030,2031],{"class":92}," item ",[47,2033,2034],{"class":2027},"in",[47,2036,2037],{"class":92}," my_list",[47,2039,2040],{"class":61},"])\n",[20,2042,2043],{},"These checks help you confirm:",[138,2045,2046,2049,2052,2060,2066],{},[141,2047,2048],{},"What values are in the list",[141,2050,2051],{},"Whether the object is really a list",[141,2053,2054,2055,2057,2058],{},"That ",[15,2056,17],{}," returns ",[15,2059,124],{},[141,2061,2062,2063,2065],{},"Whether ",[15,2064,1228],{}," works better for your case",[141,2067,2068],{},"Whether the list contains mixed data types",[20,2070,2071,2072,2074],{},"If your problem is caused by incompatible values, see a guide for fixing sorting-related ",[15,2073,1574],{}," problems.",[33,2076,2078],{"id":2077},"faq","FAQ",[1404,2080,2082,2083,2085],{"id":2081},"does-listsort-return-a-new-list","Does ",[15,2084,24],{}," return a new list?",[20,2087,2088,2089,89],{},"No. It changes the original list and returns ",[15,2090,124],{},[1404,2092,2094,2095,1233,2097,2099],{"id":2093},"what-is-the-difference-between-sort-and-sorted","What is the difference between ",[15,2096,17],{},[15,2098,1228],{},"?",[20,2101,2102,2104,2105,2107],{},[15,2103,17],{}," changes the list itself. ",[15,2106,1228],{}," creates and returns a new sorted list.",[1404,2109,2111],{"id":2110},"how-do-i-sort-in-reverse-order","How do I sort in reverse order?",[20,2113,2114],{},"Use:",[38,2116,2118],{"className":40,"code":2117,"language":42,"meta":43,"style":43},"my_list.sort(reverse=True)\n",[15,2119,2120],{"__ignoreMap":43},[47,2121,2122,2124,2126,2128,2130,2132,2134,2136],{"class":49,"line":50},[47,2123,269],{"class":53},[47,2125,89],{"class":61},[47,2127,93],{"class":92},[47,2129,106],{"class":61},[47,2131,362],{"class":278},[47,2133,58],{"class":57},[47,2135,367],{"class":284},[47,2137,216],{"class":61},[1404,2139,2141],{"id":2140},"how-do-i-sort-strings-without-case-problems","How do I sort strings without case problems?",[20,2143,2114],{},[38,2145,2147],{"className":40,"code":2146,"language":42,"meta":43,"style":43},"my_list.sort(key=str.lower)\n",[15,2148,2149],{"__ignoreMap":43},[47,2150,2151,2153,2155,2157,2159,2161,2163,2165,2167,2169],{"class":49,"line":50},[47,2152,269],{"class":53},[47,2154,89],{"class":61},[47,2156,93],{"class":92},[47,2158,106],{"class":61},[47,2160,279],{"class":278},[47,2162,58],{"class":57},[47,2164,883],{"class":882},[47,2166,89],{"class":61},[47,2168,889],{"class":888},[47,2170,216],{"class":61},[20,2172,2173],{},"This sorts in a case-insensitive way.",[1404,2175,2177,2178,2180],{"id":2176},"why-do-i-get-a-typeerror-when-sorting","Why do I get a ",[15,2179,1574],{}," when sorting?",[20,2182,2183],{},"Your list may contain values that Python cannot compare directly, such as strings and integers together.",[33,2185,2187],{"id":2186},"see-also","See also",[138,2189,2190,2195,2201,2205],{},[141,2191,2192],{},[252,2193,2194],{"href":607},"How to sort a list in Python",[141,2196,2197],{},[252,2198,1386,2199,1389],{"href":1385},[15,2200,1228],{},[141,2202,2203],{},[252,2204,255],{"href":254},[141,2206,2207],{},[252,2208,1393],{"href":1392},[2210,2211,2212],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}",{"title":43,"searchDepth":83,"depth":83,"links":2214},[2215,2216,2218,2219,2220,2221,2223,2225,2236,2246],{"id":35,"depth":83,"text":36},{"id":127,"depth":83,"text":2217},"What list.sort() does",{"id":258,"depth":83,"text":259},{"id":415,"depth":83,"text":416},{"id":611,"depth":83,"text":612},{"id":949,"depth":83,"text":2222},"Using the key argument",{"id":1222,"depth":83,"text":2224},"list.sort() vs sorted()",{"id":1396,"depth":83,"text":1397,"children":2226},[2227,2229,2230,2232,2234,2235],{"id":1406,"depth":99,"text":2228},"Assigning the result of sort()",{"id":1522,"depth":99,"text":1523},{"id":1578,"depth":99,"text":2231},"Forgetting that sort() only works on lists",{"id":1746,"depth":99,"text":2233},"Not using key when custom sorting is needed",{"id":1833,"depth":99,"text":1834},{"id":1943,"depth":99,"text":1944},{"id":2077,"depth":83,"text":2078,"children":2237},[2238,2240,2242,2243,2244],{"id":2081,"depth":99,"text":2239},"Does list.sort() return a new list?",{"id":2093,"depth":99,"text":2241},"What is the difference between sort() and sorted()?",{"id":2110,"depth":99,"text":2111},{"id":2140,"depth":99,"text":2141},{"id":2176,"depth":99,"text":2245},"Why do I get a TypeError when sorting?",{"id":2186,"depth":83,"text":2187},"Master python list sort method in our comprehensive Python beginner guide.","md",{},"\u002Freference\u002Fpython-list-sort-method",{"title":5,"description":2247},"reference\u002Fpython-list-sort-method","nuiIwWy1KS8_euTEqMoYpg2B6j3JT08NKrBSVKMUQzs",1777585509721]