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