[{"data":1,"prerenderedAt":1325},["ShallowReactive",2],{"blog-\u002Fblog\u002Fpython-list-vs-tuple-vs-set":3},{"id":4,"title":5,"body":6,"description":1312,"difficulty":1313,"extension":1314,"framework":1315,"frameworkSlug":246,"meta":1316,"navigation":333,"order":337,"path":1317,"qaPath":412,"seo":1318,"stem":1319,"subtopic":1320,"topic":1321,"topicSlug":1322,"updated":1323,"__hash__":1324},"blog\u002Fblog\u002Fpython-list-vs-tuple-vs-set.md","Python list vs tuple vs set — Choosing the Right Data Structure",{"type":7,"value":8,"toc":1298},"minimark",[9,14,38,42,221,227,241,375,390,403,414,420,434,600,615,626,634,640,657,847,850,947,958,965,973,981,995,1068,1076,1080,1083,1120,1270,1274,1294],[10,11,13],"h2",{"id":12},"three-containers-three-different-contracts","Three containers, three different contracts",[15,16,17,18,25,26,31,32,37],"p",{},"Python gives you three built-in containers that beginners often use interchangeably:\n",[19,20,21],"strong",{},[22,23,24],"code",{},"list",", ",[19,27,28],{},[22,29,30],{},"tuple",", and ",[19,33,34],{},[22,35,36],{},"set",". They look superficially similar — you can loop\nover all three — but they make fundamentally different promises about mutability,\nordering, and lookup speed. Picking the wrong one leads to subtle bugs, slow code, and\ninstant red flags in interviews. This guide untangles each contract and gives you a\ndecision rule that makes the right choice obvious.",[10,39,41],{"id":40},"quick-reference-comparison","Quick-reference comparison",[43,44,45,67],"table",{},[46,47,48],"thead",{},[49,50,51,55,59,63],"tr",{},[52,53,54],"th",{},"Property",[52,56,57],{},[22,58,24],{},[52,60,61],{},[22,62,30],{},[52,64,65],{},[22,66,36],{},[68,69,70,87,100,114,135,152,166,179,195],"tbody",{},[49,71,72,78,81,84],{},[73,74,75],"td",{},[19,76,77],{},"Mutable?",[73,79,80],{},"Yes",[73,82,83],{},"No",[73,85,86],{},"Yes (elements must be immutable)",[49,88,89,94,96,98],{},[73,90,91],{},[19,92,93],{},"Ordered?",[73,95,80],{},[73,97,80],{},[73,99,83],{},[49,101,102,107,109,111],{},[73,103,104],{},[19,105,106],{},"Allows duplicates?",[73,108,80],{},[73,110,80],{},[73,112,113],{},"No — silently deduplicates",[49,115,116,121,128,133],{},[73,117,118],{},[19,119,120],{},"Indexable?",[73,122,123,124,127],{},"Yes (",[22,125,126],{},"a[0]",")",[73,129,123,130,127],{},[22,131,132],{},"t[0]",[73,134,83],{},[49,136,137,142,145,147],{},[73,138,139],{},[19,140,141],{},"Membership test",[73,143,144],{},"O(n)",[73,146,144],{},[73,148,149],{},[19,150,151],{},"O(1) average",[49,153,154,159,161,164],{},[73,155,156],{},[19,157,158],{},"Hashable?",[73,160,83],{},[73,162,163],{},"Yes (if all elements are)",[73,165,83],{},[49,167,168,173,175,177],{},[73,169,170],{},[19,171,172],{},"Can be dict key?",[73,174,83],{},[73,176,80],{},[73,178,83],{},[49,180,181,186,189,192],{},[73,182,183],{},[19,184,185],{},"Typical use",[73,187,188],{},"Growing collection",[73,190,191],{},"Fixed record",[73,193,194],{},"Membership \u002F dedup",[49,196,197,202,207,216],{},[73,198,199],{},[19,200,201],{},"Literal syntax",[73,203,204],{},[22,205,206],{},"[1, 2, 3]",[73,208,209,212,213],{},[22,210,211],{},"(1, 2, 3)"," or ",[22,214,215],{},"1, 2, 3",[73,217,218],{},[22,219,220],{},"{1, 2, 3}",[10,222,224,226],{"id":223},"list-the-mutable-ordered-sequence",[22,225,24],{}," — the mutable, ordered sequence",[15,228,229,230,232,233,236,237,240],{},"A ",[22,231,24],{}," holds a ",[19,234,235],{},"dynamic sequence of references"," to any Python objects, in the order\nyou add them. Use it when the collection needs to ",[19,238,239],{},"grow, shrink, or be reordered",".",[242,243,248],"pre",{"className":244,"code":245,"language":246,"meta":247,"style":247},"language-python shiki shiki-themes github-light github-dark","scores = [90, 85, 70]\nscores.append(60)        # mutate freely\nscores.sort()            # [60, 70, 85, 90]\nscores[0] = 55           # reassign any element\n\n# lists allow duplicates and mixed types\nitems = [1, \"hello\", 1, None]  # valid\n","python","",[22,249,250,283,299,308,328,335,341],{"__ignoreMap":247},[251,252,255,259,263,266,270,272,275,277,280],"span",{"class":253,"line":254},"line",1,[251,256,258],{"class":257},"sVt8B","scores ",[251,260,262],{"class":261},"szBVR","=",[251,264,265],{"class":257}," [",[251,267,269],{"class":268},"sj4cs","90",[251,271,25],{"class":257},[251,273,274],{"class":268},"85",[251,276,25],{"class":257},[251,278,279],{"class":268},"70",[251,281,282],{"class":257},"]\n",[251,284,286,289,292,295],{"class":253,"line":285},2,[251,287,288],{"class":257},"scores.append(",[251,290,291],{"class":268},"60",[251,293,294],{"class":257},")        ",[251,296,298],{"class":297},"sJ8bj","# mutate freely\n",[251,300,302,305],{"class":253,"line":301},3,[251,303,304],{"class":257},"scores.sort()            ",[251,306,307],{"class":297},"# [60, 70, 85, 90]\n",[251,309,311,314,317,320,322,325],{"class":253,"line":310},4,[251,312,313],{"class":257},"scores[",[251,315,316],{"class":268},"0",[251,318,319],{"class":257},"] ",[251,321,262],{"class":261},[251,323,324],{"class":268}," 55",[251,326,327],{"class":297},"           # reassign any element\n",[251,329,331],{"class":253,"line":330},5,[251,332,334],{"emptyLinePlaceholder":333},true,"\n",[251,336,338],{"class":253,"line":337},6,[251,339,340],{"class":297},"# lists allow duplicates and mixed types\n",[251,342,344,347,349,351,354,356,360,362,364,366,369,372],{"class":253,"line":343},7,[251,345,346],{"class":257},"items ",[251,348,262],{"class":261},[251,350,265],{"class":257},[251,352,353],{"class":268},"1",[251,355,25],{"class":257},[251,357,359],{"class":358},"sZZnC","\"hello\"",[251,361,25],{"class":257},[251,363,353],{"class":268},[251,365,25],{"class":257},[251,367,368],{"class":268},"None",[251,370,371],{"class":257},"]  ",[251,373,374],{"class":297},"# valid\n",[15,376,377,378,381,382,385,386,389],{},"The most common interview trap: ",[19,379,380],{},"appending to the front"," (",[22,383,384],{},"insert(0, x)",") is O(n)\nbecause every element shifts right. Use ",[22,387,388],{},"collections.deque"," for fast front insertions.",[15,391,392,395,396,398,399,402],{},[19,393,394],{},"Rule of thumb:"," reach for a ",[22,397,24],{}," when you have a ",[19,400,401],{},"homogeneous, changing collection","\nthat you'll add to, sort, or filter — the default when you're unsure.",[404,405,406],"blockquote",{},[15,407,408,409],{},"Deep dive: ",[410,411,413],"a",{"href":412},"\u002Fpython\u002Fdata-structures\u002Flists","Lists & Slicing interview questions",[10,415,417,419],{"id":416},"tuple-the-immutable-record",[22,418,30],{}," — the immutable record",[15,421,229,422,424,425,428,429,433],{},[22,423,30],{}," is an ",[19,426,427],{},"immutable",", fixed-length sequence. Its slots can't be reassigned after\ncreation, which makes it the right structure for data that ",[430,431,432],"em",{},"shouldn't"," change — coordinates,\ndatabase rows, function return values, dictionary keys.",[242,435,437],{"className":244,"code":436,"language":246,"meta":247,"style":247},"point = (3.0, 4.0)          # fixed record — a 2D coordinate\nx, y = point                # tuple unpacking (clean, idiomatic)\n\n# tuples as dict keys — works because they're hashable\ndistances = {(0, 0): 0, (3, 4): 5.0}\n\n# immutability is shallow — a tuple of lists is mutable inside\nt = ([1, 2], [3, 4])\nt[0].append(99)             # allowed — mutates the list, not the tuple slot\nt[0] = []                   # TypeError — can't reassign the slot itself\n",[22,438,439,462,475,479,484,524,528,533,563,583],{"__ignoreMap":247},[251,440,441,444,446,448,451,453,456,459],{"class":253,"line":254},[251,442,443],{"class":257},"point ",[251,445,262],{"class":261},[251,447,381],{"class":257},[251,449,450],{"class":268},"3.0",[251,452,25],{"class":257},[251,454,455],{"class":268},"4.0",[251,457,458],{"class":257},")          ",[251,460,461],{"class":297},"# fixed record — a 2D coordinate\n",[251,463,464,467,469,472],{"class":253,"line":285},[251,465,466],{"class":257},"x, y ",[251,468,262],{"class":261},[251,470,471],{"class":257}," point                ",[251,473,474],{"class":297},"# tuple unpacking (clean, idiomatic)\n",[251,476,477],{"class":253,"line":301},[251,478,334],{"emptyLinePlaceholder":333},[251,480,481],{"class":253,"line":310},[251,482,483],{"class":297},"# tuples as dict keys — works because they're hashable\n",[251,485,486,489,491,494,496,498,500,503,505,508,511,513,516,518,521],{"class":253,"line":330},[251,487,488],{"class":257},"distances ",[251,490,262],{"class":261},[251,492,493],{"class":257}," {(",[251,495,316],{"class":268},[251,497,25],{"class":257},[251,499,316],{"class":268},[251,501,502],{"class":257},"): ",[251,504,316],{"class":268},[251,506,507],{"class":257},", (",[251,509,510],{"class":268},"3",[251,512,25],{"class":257},[251,514,515],{"class":268},"4",[251,517,502],{"class":257},[251,519,520],{"class":268},"5.0",[251,522,523],{"class":257},"}\n",[251,525,526],{"class":253,"line":337},[251,527,334],{"emptyLinePlaceholder":333},[251,529,530],{"class":253,"line":343},[251,531,532],{"class":297},"# immutability is shallow — a tuple of lists is mutable inside\n",[251,534,536,539,541,544,546,548,551,554,556,558,560],{"class":253,"line":535},8,[251,537,538],{"class":257},"t ",[251,540,262],{"class":261},[251,542,543],{"class":257}," ([",[251,545,353],{"class":268},[251,547,25],{"class":257},[251,549,550],{"class":268},"2",[251,552,553],{"class":257},"], [",[251,555,510],{"class":268},[251,557,25],{"class":257},[251,559,515],{"class":268},[251,561,562],{"class":257},"])\n",[251,564,566,569,571,574,577,580],{"class":253,"line":565},9,[251,567,568],{"class":257},"t[",[251,570,316],{"class":268},[251,572,573],{"class":257},"].append(",[251,575,576],{"class":268},"99",[251,578,579],{"class":257},")             ",[251,581,582],{"class":297},"# allowed — mutates the list, not the tuple slot\n",[251,584,586,588,590,592,594,597],{"class":253,"line":585},10,[251,587,568],{"class":257},[251,589,316],{"class":268},[251,591,319],{"class":257},[251,593,262],{"class":261},[251,595,596],{"class":257}," []                   ",[251,598,599],{"class":297},"# TypeError — can't reassign the slot itself\n",[15,601,602,603,606,607,610,611,614],{},"Because all elements must be hashable for the tuple to be hashable, ",[22,604,605],{},"(1, [2, 3])"," raises\n",[22,608,609],{},"TypeError"," on ",[22,612,613],{},"hash()"," — a classic gotcha.",[15,616,617,395,619,621,622,625],{},[19,618,394],{},[22,620,30],{}," when the data is a ",[19,623,624],{},"fixed bundle that won't\nchange"," — if you'd describe it as \"a record\" or \"a point\", it's a tuple.",[404,627,628],{},[15,629,408,630],{},[410,631,633],{"href":632},"\u002Fpython\u002Fdata-structures\u002Ftuples","Tuples & Named Tuples interview questions",[10,635,637,639],{"id":636},"set-the-unordered-deduplicated-membership-checker",[22,638,36],{}," — the unordered, deduplicated membership checker",[15,641,229,642,644,645,648,649,652,653,656],{},[22,643,36],{}," is a ",[19,646,647],{},"hash table of unique values"," with no defined order. Its superpower is\n",[19,650,651],{},"O(1) average membership testing"," — regardless of how many elements are in the set,\n",[22,654,655],{},"x in s"," costs the same.",[242,658,660],{"className":244,"code":659,"language":246,"meta":247,"style":247},"seen = set()\nseen.add(1)\nseen.add(2)\nseen.add(1)          # silently ignored — sets store unique elements only\nprint(seen)          # {1, 2}  (order not guaranteed)\n\n# O(1) membership vs O(n) for lists\nbig_list = list(range(1_000_000))\nbig_set  = set(big_list)\n999_999 in big_list  # scans up to 1 million elements\n999_999 in big_set   # one hash lookup\n\n# fast deduplication\nnames = [\"alice\", \"bob\", \"alice\", \"carol\"]\nunique = list(set(names))   # [\"alice\", \"bob\", \"carol\"] — order lost\n",[22,661,662,675,685,693,704,715,719,724,748,760,774,787,792,798,827],{"__ignoreMap":247},[251,663,664,667,669,672],{"class":253,"line":254},[251,665,666],{"class":257},"seen ",[251,668,262],{"class":261},[251,670,671],{"class":268}," set",[251,673,674],{"class":257},"()\n",[251,676,677,680,682],{"class":253,"line":285},[251,678,679],{"class":257},"seen.add(",[251,681,353],{"class":268},[251,683,684],{"class":257},")\n",[251,686,687,689,691],{"class":253,"line":301},[251,688,679],{"class":257},[251,690,550],{"class":268},[251,692,684],{"class":257},[251,694,695,697,699,701],{"class":253,"line":310},[251,696,679],{"class":257},[251,698,353],{"class":268},[251,700,458],{"class":257},[251,702,703],{"class":297},"# silently ignored — sets store unique elements only\n",[251,705,706,709,712],{"class":253,"line":330},[251,707,708],{"class":268},"print",[251,710,711],{"class":257},"(seen)          ",[251,713,714],{"class":297},"# {1, 2}  (order not guaranteed)\n",[251,716,717],{"class":253,"line":337},[251,718,334],{"emptyLinePlaceholder":333},[251,720,721],{"class":253,"line":343},[251,722,723],{"class":297},"# O(1) membership vs O(n) for lists\n",[251,725,726,729,731,734,737,740,742,745],{"class":253,"line":535},[251,727,728],{"class":257},"big_list ",[251,730,262],{"class":261},[251,732,733],{"class":268}," list",[251,735,736],{"class":257},"(",[251,738,739],{"class":268},"range",[251,741,736],{"class":257},[251,743,744],{"class":268},"1_000_000",[251,746,747],{"class":257},"))\n",[251,749,750,753,755,757],{"class":253,"line":565},[251,751,752],{"class":257},"big_set  ",[251,754,262],{"class":261},[251,756,671],{"class":268},[251,758,759],{"class":257},"(big_list)\n",[251,761,762,765,768,771],{"class":253,"line":585},[251,763,764],{"class":268},"999_999",[251,766,767],{"class":261}," in",[251,769,770],{"class":257}," big_list  ",[251,772,773],{"class":297},"# scans up to 1 million elements\n",[251,775,777,779,781,784],{"class":253,"line":776},11,[251,778,764],{"class":268},[251,780,767],{"class":261},[251,782,783],{"class":257}," big_set   ",[251,785,786],{"class":297},"# one hash lookup\n",[251,788,790],{"class":253,"line":789},12,[251,791,334],{"emptyLinePlaceholder":333},[251,793,795],{"class":253,"line":794},13,[251,796,797],{"class":297},"# fast deduplication\n",[251,799,801,804,806,808,811,813,816,818,820,822,825],{"class":253,"line":800},14,[251,802,803],{"class":257},"names ",[251,805,262],{"class":261},[251,807,265],{"class":257},[251,809,810],{"class":358},"\"alice\"",[251,812,25],{"class":257},[251,814,815],{"class":358},"\"bob\"",[251,817,25],{"class":257},[251,819,810],{"class":358},[251,821,25],{"class":257},[251,823,824],{"class":358},"\"carol\"",[251,826,282],{"class":257},[251,828,830,833,835,837,839,841,844],{"class":253,"line":829},15,[251,831,832],{"class":257},"unique ",[251,834,262],{"class":261},[251,836,733],{"class":268},[251,838,736],{"class":257},[251,840,36],{"class":268},[251,842,843],{"class":257},"(names))   ",[251,845,846],{"class":297},"# [\"alice\", \"bob\", \"carol\"] — order lost\n",[15,848,849],{},"Sets also support the classic mathematical operations:",[242,851,853],{"className":244,"code":852,"language":246,"meta":247,"style":247},"a = {1, 2, 3}\nb = {2, 3, 4}\na | b   # {1, 2, 3, 4}  union\na & b   # {2, 3}        intersection\na - b   # {1}           difference\na ^ b   # {1, 4}        symmetric difference\n",[22,854,855,877,898,911,923,935],{"__ignoreMap":247},[251,856,857,860,862,865,867,869,871,873,875],{"class":253,"line":254},[251,858,859],{"class":257},"a ",[251,861,262],{"class":261},[251,863,864],{"class":257}," {",[251,866,353],{"class":268},[251,868,25],{"class":257},[251,870,550],{"class":268},[251,872,25],{"class":257},[251,874,510],{"class":268},[251,876,523],{"class":257},[251,878,879,882,884,886,888,890,892,894,896],{"class":253,"line":285},[251,880,881],{"class":257},"b ",[251,883,262],{"class":261},[251,885,864],{"class":257},[251,887,550],{"class":268},[251,889,25],{"class":257},[251,891,510],{"class":268},[251,893,25],{"class":257},[251,895,515],{"class":268},[251,897,523],{"class":257},[251,899,900,902,905,908],{"class":253,"line":301},[251,901,859],{"class":257},[251,903,904],{"class":261},"|",[251,906,907],{"class":257}," b   ",[251,909,910],{"class":297},"# {1, 2, 3, 4}  union\n",[251,912,913,915,918,920],{"class":253,"line":310},[251,914,859],{"class":257},[251,916,917],{"class":261},"&",[251,919,907],{"class":257},[251,921,922],{"class":297},"# {2, 3}        intersection\n",[251,924,925,927,930,932],{"class":253,"line":330},[251,926,859],{"class":257},[251,928,929],{"class":261},"-",[251,931,907],{"class":257},[251,933,934],{"class":297},"# {1}           difference\n",[251,936,937,939,942,944],{"class":253,"line":337},[251,938,859],{"class":257},[251,940,941],{"class":261},"^",[251,943,907],{"class":257},[251,945,946],{"class":297},"# {1, 4}        symmetric difference\n",[15,948,949,950,953,954,957],{},"Because sets use hashing internally, ",[19,951,952],{},"only hashable types can be elements"," — you can't\nhave a set of lists. Use ",[22,955,956],{},"frozenset"," when you need an immutable, hashable set (e.g., as a\ndict key).",[15,959,960,395,962,964],{},[19,961,394],{},[22,963,36],{}," when the question is \"is X in this collection?\" or\n\"give me the unique items\" — never when order or duplicates matter.",[404,966,967],{},[15,968,408,969],{},[410,970,972],{"href":971},"\u002Fpython\u002Fdata-structures\u002Fsets","Sets & Frozensets interview questions",[10,974,976,977,980],{"id":975},"what-about-dict","What about ",[22,978,979],{},"dict","?",[15,982,983,984,986,987,990,991,994],{},"Dictionaries belong in this conversation too. A ",[22,985,979],{}," is essentially a set of ",[19,988,989],{},"unique\nkeys",", each mapped to a value. Since Python 3.7, insertion order is preserved. Use it\nwhen you need a ",[19,992,993],{},"key → value mapping",", not just membership.",[242,996,998],{"className":244,"code":997,"language":246,"meta":247,"style":247},"# prefer dict when you need to look up a value, not just check presence\ncache = {}\ncache[\"user_42\"] = {\"name\": \"Alice\", \"age\": 30}\ncache.get(\"user_99\", None)   # safe lookup, no KeyError\n",[22,999,1000,1005,1015,1050],{"__ignoreMap":247},[251,1001,1002],{"class":253,"line":254},[251,1003,1004],{"class":297},"# prefer dict when you need to look up a value, not just check presence\n",[251,1006,1007,1010,1012],{"class":253,"line":285},[251,1008,1009],{"class":257},"cache ",[251,1011,262],{"class":261},[251,1013,1014],{"class":257}," {}\n",[251,1016,1017,1020,1023,1025,1027,1029,1032,1035,1038,1040,1043,1045,1048],{"class":253,"line":301},[251,1018,1019],{"class":257},"cache[",[251,1021,1022],{"class":358},"\"user_42\"",[251,1024,319],{"class":257},[251,1026,262],{"class":261},[251,1028,864],{"class":257},[251,1030,1031],{"class":358},"\"name\"",[251,1033,1034],{"class":257},": ",[251,1036,1037],{"class":358},"\"Alice\"",[251,1039,25],{"class":257},[251,1041,1042],{"class":358},"\"age\"",[251,1044,1034],{"class":257},[251,1046,1047],{"class":268},"30",[251,1049,523],{"class":257},[251,1051,1052,1055,1058,1060,1062,1065],{"class":253,"line":310},[251,1053,1054],{"class":257},"cache.get(",[251,1056,1057],{"class":358},"\"user_99\"",[251,1059,25],{"class":257},[251,1061,368],{"class":268},[251,1063,1064],{"class":257},")   ",[251,1066,1067],{"class":297},"# safe lookup, no KeyError\n",[404,1069,1070],{},[15,1071,408,1072],{},[410,1073,1075],{"href":1074},"\u002Fpython\u002Fdata-structures\u002Fdictionaries","Dictionaries interview questions",[10,1077,1079],{"id":1078},"the-decision-rule","The decision rule",[15,1081,1082],{},"Answer three questions in order:",[1084,1085,1086,1095,1113],"ol",{},[1087,1088,1089,1092,1093],"li",{},[19,1090,1091],{},"Do I need key → value mapping?"," → ",[22,1094,979],{},[1087,1096,1097,1100],{},[19,1098,1099],{},"Will the collection change, or do I need ordering \u002F indexing?",[1101,1102,1103,1108],"ul",{},[1087,1104,1105,1106],{},"Yes, needs to change or be indexed → ",[22,1107,24],{},[1087,1109,1110,1111],{},"No, it's a fixed record → ",[22,1112,30],{},[1087,1114,1115,1092,1118],{},[19,1116,1117],{},"Do I only need to know \"is X a member?\" or \"what are the unique values?\"",[22,1119,36],{},[242,1121,1123],{"className":244,"code":1122,"language":246,"meta":247,"style":247},"# Q1: mapping needed? → dict\nuser = {\"name\": \"Alice\", \"age\": 30}\n\n# Q2a: changing collection? → list\nqueue = [\"task_a\", \"task_b\"]\nqueue.append(\"task_c\")\n\n# Q2b: fixed record? → tuple\nrgb = (255, 128, 0)           # color — never reassigns channels\n\n# Q3: membership \u002F unique? → set\nvisited_urls = set()\nif url not in visited_urls:\n    visited_urls.add(url)\n",[22,1124,1125,1130,1155,1159,1164,1183,1193,1197,1202,1229,1233,1238,1249,1265],{"__ignoreMap":247},[251,1126,1127],{"class":253,"line":254},[251,1128,1129],{"class":297},"# Q1: mapping needed? → dict\n",[251,1131,1132,1135,1137,1139,1141,1143,1145,1147,1149,1151,1153],{"class":253,"line":285},[251,1133,1134],{"class":257},"user ",[251,1136,262],{"class":261},[251,1138,864],{"class":257},[251,1140,1031],{"class":358},[251,1142,1034],{"class":257},[251,1144,1037],{"class":358},[251,1146,25],{"class":257},[251,1148,1042],{"class":358},[251,1150,1034],{"class":257},[251,1152,1047],{"class":268},[251,1154,523],{"class":257},[251,1156,1157],{"class":253,"line":301},[251,1158,334],{"emptyLinePlaceholder":333},[251,1160,1161],{"class":253,"line":310},[251,1162,1163],{"class":297},"# Q2a: changing collection? → list\n",[251,1165,1166,1169,1171,1173,1176,1178,1181],{"class":253,"line":330},[251,1167,1168],{"class":257},"queue ",[251,1170,262],{"class":261},[251,1172,265],{"class":257},[251,1174,1175],{"class":358},"\"task_a\"",[251,1177,25],{"class":257},[251,1179,1180],{"class":358},"\"task_b\"",[251,1182,282],{"class":257},[251,1184,1185,1188,1191],{"class":253,"line":337},[251,1186,1187],{"class":257},"queue.append(",[251,1189,1190],{"class":358},"\"task_c\"",[251,1192,684],{"class":257},[251,1194,1195],{"class":253,"line":343},[251,1196,334],{"emptyLinePlaceholder":333},[251,1198,1199],{"class":253,"line":535},[251,1200,1201],{"class":297},"# Q2b: fixed record? → tuple\n",[251,1203,1204,1207,1209,1211,1214,1216,1219,1221,1223,1226],{"class":253,"line":565},[251,1205,1206],{"class":257},"rgb ",[251,1208,262],{"class":261},[251,1210,381],{"class":257},[251,1212,1213],{"class":268},"255",[251,1215,25],{"class":257},[251,1217,1218],{"class":268},"128",[251,1220,25],{"class":257},[251,1222,316],{"class":268},[251,1224,1225],{"class":257},")           ",[251,1227,1228],{"class":297},"# color — never reassigns channels\n",[251,1230,1231],{"class":253,"line":585},[251,1232,334],{"emptyLinePlaceholder":333},[251,1234,1235],{"class":253,"line":776},[251,1236,1237],{"class":297},"# Q3: membership \u002F unique? → set\n",[251,1239,1240,1243,1245,1247],{"class":253,"line":789},[251,1241,1242],{"class":257},"visited_urls ",[251,1244,262],{"class":261},[251,1246,671],{"class":268},[251,1248,674],{"class":257},[251,1250,1251,1254,1257,1260,1262],{"class":253,"line":794},[251,1252,1253],{"class":261},"if",[251,1255,1256],{"class":257}," url ",[251,1258,1259],{"class":261},"not",[251,1261,767],{"class":261},[251,1263,1264],{"class":257}," visited_urls:\n",[251,1266,1267],{"class":253,"line":800},[251,1268,1269],{"class":257},"    visited_urls.add(url)\n",[10,1271,1273],{"id":1272},"recap","Recap",[15,1275,229,1276,1280,1281,1285,1286,1290,1291,1293],{},[19,1277,1278],{},[22,1279,24],{}," is mutable, ordered, and allows duplicates — the default workhorse for\ngrowing collections. A ",[19,1282,1283],{},[22,1284,30],{}," is immutable, ordered, hashable, and faster — use it\nfor fixed records and dictionary keys. A ",[19,1287,1288],{},[22,1289,36],{}," is unordered, deduplicated, and offers\nO(1) membership — reach for it whenever you need fast \"is X in here?\" or unique-values\nlogic. When you need key-value pairs, add ",[22,1292,979],{}," to the toolkit. The deciding factor is\nusually mutability first, then whether order or uniqueness matters more.",[1295,1296,1297],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}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);}",{"title":247,"searchDepth":285,"depth":285,"links":1299},[1300,1301,1302,1304,1306,1308,1310,1311],{"id":12,"depth":285,"text":13},{"id":40,"depth":285,"text":41},{"id":223,"depth":285,"text":1303},"list — the mutable, ordered sequence",{"id":416,"depth":285,"text":1305},"tuple — the immutable record",{"id":636,"depth":285,"text":1307},"set — the unordered, deduplicated membership checker",{"id":975,"depth":285,"text":1309},"What about dict?",{"id":1078,"depth":285,"text":1079},{"id":1272,"depth":285,"text":1273},"Python list vs tuple vs set explained — mutability, hashability, O(1) membership testing, and the one-question decision rule that makes the right choice obvious in code and interviews.","easy","md","Python",{},"\u002Fblog\u002Fpython-list-vs-tuple-vs-set",{"title":5,"description":1312},"blog\u002Fpython-list-vs-tuple-vs-set","List vs Tuple vs Set","Data Structures","data-structures","2026-06-21","-8XsAZG-EG9mWkWTpjWZZWFx1zdbZqIlAe29JhVQEzE",1782244088015]