[{"data":1,"prerenderedAt":2148},["ShallowReactive",2],{"navigation_docs":3,"-fundamentals-maps":377,"-fundamentals-maps-surround":2143},[4,39,114,144,184,244,293,362],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":6},"Getting Started",false,"\u002Fgetting-started","1.getting-started",[10,15,20,25,30,35],{"title":11,"path":12,"stem":13,"icon":14},"Learning Path","\u002Fgetting-started\u002Flearning-path","1.getting-started\u002F1.learning-path","i-lucide-map",{"title":16,"path":17,"stem":18,"icon":19},"Introduction","\u002Fgetting-started\u002Fintroduction","1.getting-started\u002F2.introduction","i-lucide-house",{"title":21,"path":22,"stem":23,"icon":24},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F3.installation","i-lucide-download",{"title":26,"path":27,"stem":28,"icon":29},"Your First Program","\u002Fgetting-started\u002Ffirst-program","1.getting-started\u002F4.first-program","i-lucide-play",{"title":31,"path":32,"stem":33,"icon":34},"Modules and Dependencies","\u002Fgetting-started\u002Fmodules-and-dependencies","1.getting-started\u002F5.modules-and-dependencies","i-lucide-package-open",{"title":36,"path":37,"stem":38,"icon":34},"Advanced Modules","\u002Fgetting-started\u002Fadvanced-modules","1.getting-started\u002F6.advanced-modules",{"title":40,"path":41,"stem":42,"children":43,"page":6},"Fundamentals","\u002Ffundamentals","2.fundamentals",[44,49,54,59,64,69,74,79,84,89,94,99,104,109],{"title":45,"path":46,"stem":47,"icon":48},"Program Structure","\u002Ffundamentals\u002Fprogram-structure","2.fundamentals\u002F1.program-structure","i-lucide-workflow",{"title":50,"path":51,"stem":52,"icon":53},"Structs and Methods","\u002Ffundamentals\u002Fstructs-and-methods","2.fundamentals\u002F10.structs-and-methods","i-lucide-box",{"title":55,"path":56,"stem":57,"icon":58},"Interfaces","\u002Ffundamentals\u002Finterfaces","2.fundamentals\u002F11.interfaces","i-lucide-plug",{"title":60,"path":61,"stem":62,"icon":63},"Error Handling","\u002Ffundamentals\u002Ferrors","2.fundamentals\u002F12.errors","i-lucide-triangle-alert",{"title":65,"path":66,"stem":67,"icon":68},"Defined Types and Type Aliases","\u002Ffundamentals\u002Fdefined-types","2.fundamentals\u002F13.defined-types","i-lucide-tags",{"title":70,"path":71,"stem":72,"icon":73},"Generics","\u002Ffundamentals\u002Fgenerics","2.fundamentals\u002F14.generics","i-lucide-blocks",{"title":75,"path":76,"stem":77,"icon":78},"Project Structure","\u002Ffundamentals\u002Fproject-structure","2.fundamentals\u002F2.project-structure","i-lucide-folder-tree",{"title":80,"path":81,"stem":82,"icon":83},"Project Layout","\u002Ffundamentals\u002Fproject-layout","2.fundamentals\u002F3.project-layout","i-lucide-layout",{"title":85,"path":86,"stem":87,"icon":88},"Variables and Data Types","\u002Ffundamentals\u002Fvariables-and-types","2.fundamentals\u002F4.variables-and-types","i-lucide-variable",{"title":90,"path":91,"stem":92,"icon":93},"Functions","\u002Ffundamentals\u002Ffunctions","2.fundamentals\u002F5.functions","i-lucide-braces",{"title":95,"path":96,"stem":97,"icon":98},"Control Statements","\u002Ffundamentals\u002Fcontrol-statements","2.fundamentals\u002F6.control-statements","i-lucide-git-branch",{"title":100,"path":101,"stem":102,"icon":103},"Pointers","\u002Ffundamentals\u002Fpointers","2.fundamentals\u002F7.pointers","i-lucide-mouse-pointer-2",{"title":105,"path":106,"stem":107,"icon":108},"Arrays and Slices","\u002Ffundamentals\u002Farrays-and-slices","2.fundamentals\u002F8.arrays-and-slices","i-lucide-list",{"title":110,"path":111,"stem":112,"icon":113},"Maps","\u002Ffundamentals\u002Fmaps","2.fundamentals\u002F9.maps","i-lucide-table-properties",{"title":115,"path":116,"stem":117,"children":118,"page":6},"Concurrency","\u002Fconcurrency","3.concurrency",[119,124,129,134,139],{"title":120,"path":121,"stem":122,"icon":123},"Concurrency Model","\u002Fconcurrency\u002Fconcurrency-model","3.concurrency\u002F1.concurrency-model","i-lucide-network",{"title":125,"path":126,"stem":127,"icon":128},"Goroutines","\u002Fconcurrency\u002Fgoroutines","3.concurrency\u002F2.goroutines","i-lucide-git-fork",{"title":130,"path":131,"stem":132,"icon":133},"Channels","\u002Fconcurrency\u002Fchannels","3.concurrency\u002F3.channels","i-lucide-arrow-left-right",{"title":135,"path":136,"stem":137,"icon":138},"Select and Cancellation","\u002Fconcurrency\u002Fselect-and-cancellation","3.concurrency\u002F4.select-and-cancellation","i-lucide-circle-stop",{"title":140,"path":141,"stem":142,"icon":143},"Synchronization","\u002Fconcurrency\u002Fsynchronization","3.concurrency\u002F5.synchronization","i-lucide-lock-keyhole",{"title":145,"path":146,"stem":147,"children":148,"page":6},"Standard Library","\u002Fstandard-library","4.standard-library",[149,154,159,164,169,174,179],{"title":150,"path":151,"stem":152,"icon":153},"Standard Library Overview","\u002Fstandard-library\u002Foverview","4.standard-library\u002F1.overview","i-lucide-library",{"title":155,"path":156,"stem":157,"icon":158},"Text and Formatting","\u002Fstandard-library\u002Ftext-and-formatting","4.standard-library\u002F2.text-and-formatting","i-lucide-text",{"title":160,"path":161,"stem":162,"icon":163},"Files and JSON","\u002Fstandard-library\u002Ffiles-and-json","4.standard-library\u002F3.files-and-json","i-lucide-file-json",{"title":165,"path":166,"stem":167,"icon":168},"HTTP Clients and Servers","\u002Fstandard-library\u002Fhttp","4.standard-library\u002F4.http","i-lucide-server",{"title":170,"path":171,"stem":172,"icon":173},"Testing","\u002Fstandard-library\u002Ftesting","4.standard-library\u002F5.testing","i-lucide-flask-conical",{"title":175,"path":176,"stem":177,"icon":178},"Command-Line Tools and Configuration","\u002Fstandard-library\u002Fcommand-line-and-configuration","4.standard-library\u002F6.command-line-and-configuration","i-lucide-terminal-square",{"title":180,"path":181,"stem":182,"icon":183},"Structured Logging","\u002Fstandard-library\u002Fstructured-logging","4.standard-library\u002F7.structured-logging","i-lucide-scroll-text",{"title":185,"path":186,"stem":187,"children":188,"page":6},"Backend Development","\u002Fbackend-development","5.backend-development",[189,194,199,204,209,214,219,224,229,234,239],{"title":190,"path":191,"stem":192,"icon":193},"Backend Roadmap","\u002Fbackend-development\u002Fbackend-roadmap","5.backend-development\u002F1.backend-roadmap","i-lucide-route",{"title":195,"path":196,"stem":197,"icon":198},"Graceful Shutdown","\u002Fbackend-development\u002Fgraceful-shutdown","5.backend-development\u002F10.graceful-shutdown","i-lucide-power",{"title":200,"path":201,"stem":202,"icon":203},"Production Checklist","\u002Fbackend-development\u002Fproduction-checklist","5.backend-development\u002F11.production-checklist","i-lucide-clipboard-check",{"title":205,"path":206,"stem":207,"icon":208},"HTTP API Design","\u002Fbackend-development\u002Fhttp-api-design","5.backend-development\u002F2.http-api-design","i-lucide-waypoints",{"title":210,"path":211,"stem":212,"icon":213},"Middleware","\u002Fbackend-development\u002Fmiddleware","5.backend-development\u002F3.middleware","i-lucide-layers-3",{"title":215,"path":216,"stem":217,"icon":218},"Validation","\u002Fbackend-development\u002Fvalidation","5.backend-development\u002F4.validation","i-lucide-list-checks",{"title":220,"path":221,"stem":222,"icon":223},"Application Wiring","\u002Fbackend-development\u002Fapplication-wiring","5.backend-development\u002F5.application-wiring","i-lucide-cable",{"title":225,"path":226,"stem":227,"icon":228},"Observability","\u002Fbackend-development\u002Fobservability","5.backend-development\u002F6.observability","i-lucide-activity",{"title":230,"path":231,"stem":232,"icon":233},"Database SQL","\u002Fbackend-development\u002Fdatabase-sql","5.backend-development\u002F7.database-sql","i-lucide-database",{"title":235,"path":236,"stem":237,"icon":238},"Transactions","\u002Fbackend-development\u002Ftransactions","5.backend-development\u002F8.transactions","i-lucide-repeat-2",{"title":240,"path":241,"stem":242,"icon":243},"Authentication and Authorization","\u002Fbackend-development\u002Fauthentication","5.backend-development\u002F9.authentication","i-lucide-shield-check",{"title":245,"path":246,"stem":247,"children":248,"page":6},"Advanced Go","\u002Fadvanced-go","6.advanced-go",[249,254,259,264,269,274,278,283,288],{"title":250,"path":251,"stem":252,"icon":253},"Advanced Go Roadmap","\u002Fadvanced-go\u002Fadvanced-roadmap","6.advanced-go\u002F1.advanced-roadmap","i-lucide-brain-circuit",{"title":255,"path":256,"stem":257,"icon":258},"Reflection","\u002Fadvanced-go\u002Freflection","6.advanced-go\u002F2.reflection","i-lucide-scan-search",{"title":260,"path":261,"stem":262,"icon":263},"Memory and Garbage Collection","\u002Fadvanced-go\u002Fmemory-and-garbage-collection","6.advanced-go\u002F3.memory-and-garbage-collection","i-lucide-memory-stick",{"title":265,"path":266,"stem":267,"icon":268},"Benchmarking and Profiling","\u002Fadvanced-go\u002Fbenchmarking-and-profiling","6.advanced-go\u002F4.benchmarking-and-profiling","i-lucide-gauge",{"title":270,"path":271,"stem":272,"icon":273},"Advanced Testing and Fuzzing","\u002Fadvanced-go\u002Fadvanced-testing-and-fuzzing","6.advanced-go\u002F5.advanced-testing-and-fuzzing","i-lucide-microscope",{"title":275,"path":276,"stem":277,"icon":48},"Advanced Concurrency","\u002Fadvanced-go\u002Fadvanced-concurrency","6.advanced-go\u002F6.advanced-concurrency",{"title":279,"path":280,"stem":281,"icon":282},"Unsafe and C Boundaries","\u002Fadvanced-go\u002Funsafe-and-cgo","6.advanced-go\u002F7.unsafe-and-cgo","i-lucide-radiation",{"title":284,"path":285,"stem":286,"icon":287},"Package and API Design","\u002Fadvanced-go\u002Fpackage-and-api-design","6.advanced-go\u002F8.package-and-api-design","i-lucide-boxes",{"title":289,"path":290,"stem":291,"icon":292},"Distributed Reliability","\u002Fadvanced-go\u002Fdistributed-reliability","6.advanced-go\u002F9.distributed-reliability","i-lucide-cloud-cog",{"title":294,"path":295,"stem":296,"children":297,"page":6},"Projects","\u002Fprojects","7.projects",[298,316,332,347],{"title":299,"path":300,"stem":301,"children":302,"icon":305},"CLI Task Manager","\u002Fprojects\u002Fcli-task-manager","7.projects\u002F1.cli-task-manager\u002Findex",[303,306,311],{"title":304,"path":300,"stem":301,"icon":305},"Project — CLI Task Manager","i-lucide-list-todo",{"title":307,"path":308,"stem":309,"icon":310},"CLI — Domain and Storage","\u002Fprojects\u002Fcli-task-manager\u002Fdomain-and-storage","7.projects\u002F1.cli-task-manager\u002F1.domain-and-storage","i-lucide-save",{"title":312,"path":313,"stem":314,"icon":315},"CLI — Commands and Tests","\u002Fprojects\u002Fcli-task-manager\u002Fcommands-and-tests","7.projects\u002F1.cli-task-manager\u002F2.commands-and-tests","i-lucide-terminal",{"title":317,"path":318,"stem":319,"children":320,"icon":323},"Concurrent URL Checker","\u002Fprojects\u002Fconcurrent-url-checker","7.projects\u002F2.concurrent-url-checker\u002Findex",[321,324,328],{"title":322,"path":318,"stem":319,"icon":323},"Project — Concurrent URL Checker","i-lucide-radar",{"title":325,"path":326,"stem":327,"icon":128},"URL Checker — Worker Pipeline","\u002Fprojects\u002Fconcurrent-url-checker\u002Fworker-pipeline","7.projects\u002F2.concurrent-url-checker\u002F1.worker-pipeline",{"title":329,"path":330,"stem":331,"icon":173},"URL Checker — Cancellation and Tests","\u002Fprojects\u002Fconcurrent-url-checker\u002Fcancellation-and-tests","7.projects\u002F2.concurrent-url-checker\u002F2.cancellation-and-tests",{"title":333,"path":334,"stem":335,"children":336},"File-backed API","\u002Fprojects\u002Ffile-backed-api","7.projects\u002F3.file-backed-api\u002Findex",[337,339,343],{"title":338,"path":334,"stem":335},"File-backed notes API",{"title":340,"path":341,"stem":342},"File store and concurrency","\u002Fprojects\u002Ffile-backed-api\u002Ffile-store-and-concurrency","7.projects\u002F3.file-backed-api\u002F1.file-store-and-concurrency",{"title":344,"path":345,"stem":346},"HTTP layer and tests","\u002Fprojects\u002Ffile-backed-api\u002Fhttp-and-tests","7.projects\u002F3.file-backed-api\u002F2.http-and-tests",{"title":348,"path":349,"stem":350,"children":351},"Production REST API","\u002Fprojects\u002Fproduction-rest-api","7.projects\u002F4.production-rest-api\u002Findex",[352,354,358],{"title":353,"path":349,"stem":350},"Production REST API capstone",{"title":355,"path":356,"stem":357},"Persistence and authentication","\u002Fprojects\u002Fproduction-rest-api\u002Fpersistence-and-auth","7.projects\u002F4.production-rest-api\u002F1.persistence-and-auth",{"title":359,"path":360,"stem":361},"Operations and release","\u002Fprojects\u002Fproduction-rest-api\u002Foperations-and-release","7.projects\u002F4.production-rest-api\u002F2.operations-and-release",{"title":363,"path":364,"stem":365,"children":366,"page":6},"Meta","\u002Fmeta","99.meta",[367,372],{"title":368,"path":369,"stem":370,"icon":371},"About","\u002Fmeta\u002Fabout","99.meta\u002F1.about","i-lucide-info",{"title":373,"path":374,"stem":375,"icon":376},"Acknowledgements","\u002Fmeta\u002Facknowledgements","99.meta\u002F2.acknowledgements","i-lucide-heart-handshake",{"id":378,"title":110,"body":379,"description":2135,"extension":2136,"links":2137,"meta":2138,"navigation":2139,"path":111,"seo":2140,"stem":112,"__hash__":2142},"docs\u002F2.fundamentals\u002F9.maps.md",{"type":380,"value":381,"toc":2118},"minimark",[382,389,394,398,402,405,496,503,507,513,619,626,630,676,688,695,799,805,809,834,837,841,890,893,1039,1043,1046,1144,1155,1159,1165,1246,1254,1264,1268,1279,1283,1286,1441,1448,1451,1549,1555,1562,1566,1573,1667,1676,1680,1687,1691,1724,1728,1734,2088,2092,2099,2108,2111,2114],[383,384],"learning-lesson-meta",{"description":385,"difficulty":386,"prerequisites":387,"time":388},"Create and use maps for fast lookup by key, and avoid the common map pitfalls.","Beginner","Arrays and Slices, Control Statements","35 minutes",[390,391,393],"h2",{"id":392},"what-you-will-learn","What you will learn",[395,396,397],"p",{},"A map stores values that you look up by a key, such as a name, an ID, or a word. This lesson covers creating maps, reading and writing entries, telling a missing key from a zero value, deleting, iterating in a stable order, the nil-map panic, and the rules about concurrent use.",[390,399,401],{"id":400},"when-to-use-a-map","When to use a map",[395,403,404],{},"A slice finds an item by its position, so finding \"Grace\" means scanning the list. A map finds an item by its key directly, so the lookup takes about the same time no matter how many entries there are. Use a map whenever you think \"look up this by that\".",[406,407,412],"pre",{"className":408,"code":409,"language":410,"meta":411,"style":411},"language-go shiki shiki-themes solarized-light material-theme one-dark-pro","ages := map[string]int{\n    \"Ada\":   36,\n    \"Grace\": 40,\n}\n","go","",[413,414,415,449,473,490],"code",{"__ignoreMap":411},[416,417,420,424,428,432,436,440,443,446],"span",{"class":418,"line":419},"line",1,[416,421,423],{"class":422},"s45-6","ages",[416,425,427],{"class":426},"su2KV"," :=",[416,429,431],{"class":430},"sEOdo"," map",[416,433,435],{"class":434},"shFME","[",[416,437,439],{"class":438},"sF6sA","string",[416,441,442],{"class":434},"]",[416,444,445],{"class":438},"int",[416,447,448],{"class":434},"{\n",[416,450,452,456,460,463,466,470],{"class":418,"line":451},2,[416,453,455],{"class":454},"sED5a","    \"",[416,457,459],{"class":458},"sVazx","Ada",[416,461,462],{"class":454},"\"",[416,464,465],{"class":434},":",[416,467,469],{"class":468},"sAJzr","   36",[416,471,472],{"class":434},",\n",[416,474,476,478,481,483,485,488],{"class":418,"line":475},3,[416,477,455],{"class":454},[416,479,480],{"class":458},"Grace",[416,482,462],{"class":454},[416,484,465],{"class":434},[416,486,487],{"class":468}," 40",[416,489,472],{"class":434},[416,491,493],{"class":418,"line":492},4,[416,494,495],{"class":434},"}\n",[395,497,498,499,502],{},"The type ",[413,500,501],{},"map[string]int"," means \"keys are strings, values are integers\". Each key appears at most once.",[390,504,506],{"id":505},"create-and-update","Create and update",[395,508,509,510,465],{},"You can start from a literal, or create an empty map with ",[413,511,512],{},"make",[406,514,516],{"className":408,"code":515,"language":410,"meta":411,"style":411},"scores := make(map[string]int)\n\nscores[\"blue\"] = 10 \u002F\u002F adds the key\nscores[\"red\"] = 8\nscores[\"blue\"]++    \u002F\u002F updates the existing key\n",[413,517,518,546,552,577,597],{"__ignoreMap":411},[416,519,520,523,525,529,532,535,537,539,541,543],{"class":418,"line":419},[416,521,522],{"class":422},"scores",[416,524,427],{"class":426},[416,526,528],{"class":527},"sisdC"," make",[416,530,531],{"class":434},"(",[416,533,534],{"class":430},"map",[416,536,435],{"class":434},[416,538,439],{"class":438},[416,540,442],{"class":434},[416,542,445],{"class":438},[416,544,545],{"class":434},")\n",[416,547,548],{"class":418,"line":451},[416,549,551],{"emptyLinePlaceholder":550},true,"\n",[416,553,554,556,558,560,563,565,567,570,573],{"class":418,"line":475},[416,555,522],{"class":422},[416,557,435],{"class":434},[416,559,462],{"class":454},[416,561,562],{"class":458},"blue",[416,564,462],{"class":454},[416,566,442],{"class":434},[416,568,569],{"class":426}," =",[416,571,572],{"class":468}," 10",[416,574,576],{"class":575},"sJsHy"," \u002F\u002F adds the key\n",[416,578,579,581,583,585,588,590,592,594],{"class":418,"line":492},[416,580,522],{"class":422},[416,582,435],{"class":434},[416,584,462],{"class":454},[416,586,587],{"class":458},"red",[416,589,462],{"class":454},[416,591,442],{"class":434},[416,593,569],{"class":426},[416,595,596],{"class":468}," 8\n",[416,598,600,602,604,606,608,610,612,616],{"class":418,"line":599},5,[416,601,522],{"class":422},[416,603,435],{"class":434},[416,605,462],{"class":454},[416,607,562],{"class":458},[416,609,462],{"class":454},[416,611,442],{"class":434},[416,613,615],{"class":614},"sRBoR","++",[416,617,618],{"class":575},"    \u002F\u002F updates the existing key\n",[395,620,621,622,625],{},"Assigning to a key either adds it or replaces its value. The number of entries is ",[413,623,624],{},"len(scores)",".",[390,627,629],{"id":628},"reading-a-value","Reading a value",[406,631,633],{"className":408,"code":632,"language":410,"meta":411,"style":411},"score := scores[\"blue\"]\nfmt.Println(score) \u002F\u002F 11\n",[413,634,635,656],{"__ignoreMap":411},[416,636,637,640,642,645,647,649,651,653],{"class":418,"line":419},[416,638,639],{"class":422},"score",[416,641,427],{"class":426},[416,643,644],{"class":422}," scores",[416,646,435],{"class":434},[416,648,462],{"class":454},[416,650,562],{"class":458},[416,652,462],{"class":454},[416,654,655],{"class":434},"]\n",[416,657,658,661,663,666,668,670,673],{"class":418,"line":451},[416,659,660],{"class":422},"fmt",[416,662,625],{"class":434},[416,664,665],{"class":527},"Println",[416,667,531],{"class":434},[416,669,639],{"class":422},[416,671,672],{"class":434},")",[416,674,675],{"class":575}," \u002F\u002F 11\n",[395,677,678,679,683,684,687],{},"If the key does not exist, you get the ",[680,681,682],"strong",{},"zero value"," of the value type, ",[413,685,686],{},"0"," here, with no error. That causes an ambiguity: did the key not exist, or is its value actually zero?",[395,689,690,691,694],{},"The ",[680,692,693],{},"comma-ok form"," settles it. A lookup can return a second value saying whether the key was found:",[406,696,698],{"className":408,"code":697,"language":410,"meta":411,"style":411},"score, ok := scores[\"green\"]\nif !ok {\n    fmt.Println(\"green has no score yet\")\n} else {\n    fmt.Println(\"green:\", score)\n}\n",[413,699,700,725,740,760,770,794],{"__ignoreMap":411},[416,701,702,704,707,710,712,714,716,718,721,723],{"class":418,"line":419},[416,703,639],{"class":422},[416,705,706],{"class":434},",",[416,708,709],{"class":422}," ok",[416,711,427],{"class":426},[416,713,644],{"class":422},[416,715,435],{"class":434},[416,717,462],{"class":454},[416,719,720],{"class":458},"green",[416,722,462],{"class":454},[416,724,655],{"class":434},[416,726,727,731,734,737],{"class":418,"line":451},[416,728,730],{"class":729},"s7Bcg","if",[416,732,733],{"class":614}," !",[416,735,736],{"class":422},"ok",[416,738,739],{"class":434}," {\n",[416,741,742,745,747,749,751,753,756,758],{"class":418,"line":475},[416,743,744],{"class":422},"    fmt",[416,746,625],{"class":434},[416,748,665],{"class":527},[416,750,531],{"class":434},[416,752,462],{"class":454},[416,754,755],{"class":458},"green has no score yet",[416,757,462],{"class":454},[416,759,545],{"class":434},[416,761,762,765,768],{"class":418,"line":492},[416,763,764],{"class":434},"}",[416,766,767],{"class":729}," else",[416,769,739],{"class":434},[416,771,772,774,776,778,780,782,785,787,789,792],{"class":418,"line":599},[416,773,744],{"class":422},[416,775,625],{"class":434},[416,777,665],{"class":527},[416,779,531],{"class":434},[416,781,462],{"class":454},[416,783,784],{"class":458},"green:",[416,786,462],{"class":454},[416,788,706],{"class":434},[416,790,791],{"class":422}," score",[416,793,545],{"class":434},[416,795,797],{"class":418,"line":796},6,[416,798,495],{"class":434},[395,800,801,802,625],{},"This is used so often that you will see a short version: ",[413,803,804],{},"if score, ok := scores[\"green\"]; ok { ... }",[390,806,808],{"id":807},"deleting","Deleting",[406,810,812],{"className":408,"code":811,"language":410,"meta":411,"style":411},"delete(scores, \"red\")\n",[413,813,814],{"__ignoreMap":411},[416,815,816,819,821,823,825,828,830,832],{"class":418,"line":419},[416,817,818],{"class":527},"delete",[416,820,531],{"class":434},[416,822,522],{"class":422},[416,824,706],{"class":434},[416,826,827],{"class":454}," \"",[416,829,587],{"class":458},[416,831,462],{"class":454},[416,833,545],{"class":434},[395,835,836],{},"Deleting a key that is not there is safe and does nothing.",[390,838,840],{"id":839},"iterating","Iterating",[406,842,844],{"className":408,"code":843,"language":410,"meta":411,"style":411},"for team, score := range scores {\n    fmt.Println(team, score)\n}\n",[413,845,846,867,886],{"__ignoreMap":411},[416,847,848,851,854,856,858,860,863,865],{"class":418,"line":419},[416,849,850],{"class":729},"for",[416,852,853],{"class":422}," team",[416,855,706],{"class":434},[416,857,791],{"class":422},[416,859,427],{"class":426},[416,861,862],{"class":729}," range",[416,864,644],{"class":422},[416,866,739],{"class":434},[416,868,869,871,873,875,877,880,882,884],{"class":418,"line":451},[416,870,744],{"class":422},[416,872,625],{"class":434},[416,874,665],{"class":527},[416,876,531],{"class":434},[416,878,879],{"class":422},"team",[416,881,706],{"class":434},[416,883,791],{"class":422},[416,885,545],{"class":434},[416,887,888],{"class":418,"line":475},[416,889,495],{"class":434},[395,891,892],{},"The order of iteration is deliberately random and can change between runs. Never rely on it. If you need stable output, collect the keys into a slice, sort it, and read the map in that order:",[406,894,896],{"className":408,"code":895,"language":410,"meta":411,"style":411},"keys := make([]string, 0, len(scores))\nfor key := range scores {\n    keys = append(keys, key)\n}\nsort.Strings(keys)\n\nfor _, key := range keys {\n    fmt.Println(key, scores[key])\n}\n",[413,897,898,929,944,964,968,984,988,1009,1034],{"__ignoreMap":411},[416,899,900,903,905,907,910,912,914,917,919,922,924,926],{"class":418,"line":419},[416,901,902],{"class":422},"keys",[416,904,427],{"class":426},[416,906,528],{"class":527},[416,908,909],{"class":434},"([]",[416,911,439],{"class":438},[416,913,706],{"class":434},[416,915,916],{"class":468}," 0",[416,918,706],{"class":434},[416,920,921],{"class":527}," len",[416,923,531],{"class":434},[416,925,522],{"class":422},[416,927,928],{"class":434},"))\n",[416,930,931,933,936,938,940,942],{"class":418,"line":451},[416,932,850],{"class":729},[416,934,935],{"class":422}," key",[416,937,427],{"class":426},[416,939,862],{"class":729},[416,941,644],{"class":422},[416,943,739],{"class":434},[416,945,946,949,951,954,956,958,960,962],{"class":418,"line":475},[416,947,948],{"class":422},"    keys",[416,950,569],{"class":426},[416,952,953],{"class":527}," append",[416,955,531],{"class":434},[416,957,902],{"class":422},[416,959,706],{"class":434},[416,961,935],{"class":422},[416,963,545],{"class":434},[416,965,966],{"class":418,"line":492},[416,967,495],{"class":434},[416,969,970,973,975,978,980,982],{"class":418,"line":599},[416,971,972],{"class":422},"sort",[416,974,625],{"class":434},[416,976,977],{"class":527},"Strings",[416,979,531],{"class":434},[416,981,902],{"class":422},[416,983,545],{"class":434},[416,985,986],{"class":418,"line":796},[416,987,551],{"emptyLinePlaceholder":550},[416,989,991,993,996,998,1000,1002,1004,1007],{"class":418,"line":990},7,[416,992,850],{"class":729},[416,994,995],{"class":422}," _",[416,997,706],{"class":434},[416,999,935],{"class":422},[416,1001,427],{"class":426},[416,1003,862],{"class":729},[416,1005,1006],{"class":422}," keys",[416,1008,739],{"class":434},[416,1010,1012,1014,1016,1018,1020,1023,1025,1027,1029,1031],{"class":418,"line":1011},8,[416,1013,744],{"class":422},[416,1015,625],{"class":434},[416,1017,665],{"class":527},[416,1019,531],{"class":434},[416,1021,1022],{"class":422},"key",[416,1024,706],{"class":434},[416,1026,644],{"class":422},[416,1028,435],{"class":434},[416,1030,1022],{"class":422},[416,1032,1033],{"class":434},"])\n",[416,1035,1037],{"class":418,"line":1036},9,[416,1038,495],{"class":434},[390,1040,1042],{"id":1041},"maps-are-shared-not-copied","Maps are shared, not copied",[395,1044,1045],{},"Assigning a map to another variable does not copy its entries. Both variables refer to the same map:",[406,1047,1049],{"className":408,"code":1048,"language":410,"meta":411,"style":411},"first := map[string]int{\"a\": 1}\nsecond := first\nsecond[\"a\"] = 99\n\nfmt.Println(first[\"a\"]) \u002F\u002F 99\n",[413,1050,1051,1085,1095,1114,1118],{"__ignoreMap":411},[416,1052,1053,1056,1058,1060,1062,1064,1066,1068,1071,1073,1076,1078,1080,1083],{"class":418,"line":419},[416,1054,1055],{"class":422},"first",[416,1057,427],{"class":426},[416,1059,431],{"class":430},[416,1061,435],{"class":434},[416,1063,439],{"class":438},[416,1065,442],{"class":434},[416,1067,445],{"class":438},[416,1069,1070],{"class":434},"{",[416,1072,462],{"class":454},[416,1074,1075],{"class":458},"a",[416,1077,462],{"class":454},[416,1079,465],{"class":434},[416,1081,1082],{"class":468}," 1",[416,1084,495],{"class":434},[416,1086,1087,1090,1092],{"class":418,"line":451},[416,1088,1089],{"class":422},"second",[416,1091,427],{"class":426},[416,1093,1094],{"class":422}," first\n",[416,1096,1097,1099,1101,1103,1105,1107,1109,1111],{"class":418,"line":475},[416,1098,1089],{"class":422},[416,1100,435],{"class":434},[416,1102,462],{"class":454},[416,1104,1075],{"class":458},[416,1106,462],{"class":454},[416,1108,442],{"class":434},[416,1110,569],{"class":426},[416,1112,1113],{"class":468}," 99\n",[416,1115,1116],{"class":418,"line":492},[416,1117,551],{"emptyLinePlaceholder":550},[416,1119,1120,1122,1124,1126,1128,1130,1132,1134,1136,1138,1141],{"class":418,"line":599},[416,1121,660],{"class":422},[416,1123,625],{"class":434},[416,1125,665],{"class":527},[416,1127,531],{"class":434},[416,1129,1055],{"class":422},[416,1131,435],{"class":434},[416,1133,462],{"class":454},[416,1135,1075],{"class":458},[416,1137,462],{"class":454},[416,1139,1140],{"class":434},"])",[416,1142,1143],{"class":575}," \u002F\u002F 99\n",[395,1145,1146,1147,1150,1151,1154],{},"The same applies when you pass a map to a function: the function can change the caller's map. To get an independent copy, use ",[413,1148,1149],{},"maps.Clone(first)"," from the standard library ",[413,1152,1153],{},"maps"," package, or build a new map and copy each pair.",[390,1156,1158],{"id":1157},"nil-maps","Nil maps",[395,1160,1161,1162,465],{},"A map you declare but never create is ",[413,1163,1164],{},"nil",[406,1166,1168],{"className":408,"code":1167,"language":410,"meta":411,"style":411},"var users map[string]string\n\nfmt.Println(users[\"42\"]) \u002F\u002F fine: prints an empty string\nusers[\"42\"] = \"Mira\"     \u002F\u002F panic\n",[413,1169,1170,1189,1193,1220],{"__ignoreMap":411},[416,1171,1172,1175,1178,1180,1182,1184,1186],{"class":418,"line":419},[416,1173,1174],{"class":430},"var",[416,1176,1177],{"class":422}," users",[416,1179,431],{"class":430},[416,1181,435],{"class":434},[416,1183,439],{"class":438},[416,1185,442],{"class":434},[416,1187,1188],{"class":438},"string\n",[416,1190,1191],{"class":418,"line":451},[416,1192,551],{"emptyLinePlaceholder":550},[416,1194,1195,1197,1199,1201,1203,1206,1208,1210,1213,1215,1217],{"class":418,"line":475},[416,1196,660],{"class":422},[416,1198,625],{"class":434},[416,1200,665],{"class":527},[416,1202,531],{"class":434},[416,1204,1205],{"class":422},"users",[416,1207,435],{"class":434},[416,1209,462],{"class":454},[416,1211,1212],{"class":458},"42",[416,1214,462],{"class":454},[416,1216,1140],{"class":434},[416,1218,1219],{"class":575}," \u002F\u002F fine: prints an empty string\n",[416,1221,1222,1224,1226,1228,1230,1232,1234,1236,1238,1241,1243],{"class":418,"line":492},[416,1223,1205],{"class":422},[416,1225,435],{"class":434},[416,1227,462],{"class":454},[416,1229,1212],{"class":458},[416,1231,462],{"class":454},[416,1233,442],{"class":434},[416,1235,569],{"class":426},[416,1237,827],{"class":454},[416,1239,1240],{"class":458},"Mira",[416,1242,462],{"class":454},[416,1244,1245],{"class":575},"     \u002F\u002F panic\n",[406,1247,1252],{"className":1248,"code":1250,"language":1251,"meta":411},[1249],"language-text","panic: assignment to entry in nil map\n","text",[413,1253,1250],{"__ignoreMap":411},[395,1255,1256,1257,1260,1261,1263],{},"Reading from, ranging over, and taking the ",[413,1258,1259],{},"len"," of a nil map are all safe. Writing is not. Create the map with ",[413,1262,512],{}," or a literal before you write to it.",[390,1265,1267],{"id":1266},"valid-keys","Valid keys",[395,1269,1270,1271,1274,1275,1278],{},"A key type must support ",[413,1272,1273],{},"==",". Strings, numbers, booleans, pointers, arrays, and structs made only of comparable fields all work. Slices, maps, and functions do not, so ",[413,1276,1277],{},"map[[]int]string"," will not compile.",[390,1280,1282],{"id":1281},"maps-of-slices-and-structs","Maps of slices and structs",[395,1284,1285],{},"A map's values can be anything, including slices, which is handy for grouping:",[406,1287,1289],{"className":408,"code":1288,"language":410,"meta":411,"style":411},"groups := make(map[string][]string)\ngroups[\"fruit\"] = append(groups[\"fruit\"], \"apple\")\ngroups[\"fruit\"] = append(groups[\"fruit\"], \"pear\")\ngroups[\"veg\"] = append(groups[\"veg\"], \"carrot\")\n",[413,1290,1291,1315,1358,1399],{"__ignoreMap":411},[416,1292,1293,1296,1298,1300,1302,1304,1306,1308,1311,1313],{"class":418,"line":419},[416,1294,1295],{"class":422},"groups",[416,1297,427],{"class":426},[416,1299,528],{"class":527},[416,1301,531],{"class":434},[416,1303,534],{"class":430},[416,1305,435],{"class":434},[416,1307,439],{"class":438},[416,1309,1310],{"class":434},"][]",[416,1312,439],{"class":438},[416,1314,545],{"class":434},[416,1316,1317,1319,1321,1323,1326,1328,1330,1332,1334,1336,1338,1340,1342,1344,1346,1349,1351,1354,1356],{"class":418,"line":451},[416,1318,1295],{"class":422},[416,1320,435],{"class":434},[416,1322,462],{"class":454},[416,1324,1325],{"class":458},"fruit",[416,1327,462],{"class":454},[416,1329,442],{"class":434},[416,1331,569],{"class":426},[416,1333,953],{"class":527},[416,1335,531],{"class":434},[416,1337,1295],{"class":422},[416,1339,435],{"class":434},[416,1341,462],{"class":454},[416,1343,1325],{"class":458},[416,1345,462],{"class":454},[416,1347,1348],{"class":434},"],",[416,1350,827],{"class":454},[416,1352,1353],{"class":458},"apple",[416,1355,462],{"class":454},[416,1357,545],{"class":434},[416,1359,1360,1362,1364,1366,1368,1370,1372,1374,1376,1378,1380,1382,1384,1386,1388,1390,1392,1395,1397],{"class":418,"line":475},[416,1361,1295],{"class":422},[416,1363,435],{"class":434},[416,1365,462],{"class":454},[416,1367,1325],{"class":458},[416,1369,462],{"class":454},[416,1371,442],{"class":434},[416,1373,569],{"class":426},[416,1375,953],{"class":527},[416,1377,531],{"class":434},[416,1379,1295],{"class":422},[416,1381,435],{"class":434},[416,1383,462],{"class":454},[416,1385,1325],{"class":458},[416,1387,462],{"class":454},[416,1389,1348],{"class":434},[416,1391,827],{"class":454},[416,1393,1394],{"class":458},"pear",[416,1396,462],{"class":454},[416,1398,545],{"class":434},[416,1400,1401,1403,1405,1407,1410,1412,1414,1416,1418,1420,1422,1424,1426,1428,1430,1432,1434,1437,1439],{"class":418,"line":492},[416,1402,1295],{"class":422},[416,1404,435],{"class":434},[416,1406,462],{"class":454},[416,1408,1409],{"class":458},"veg",[416,1411,462],{"class":454},[416,1413,442],{"class":434},[416,1415,569],{"class":426},[416,1417,953],{"class":527},[416,1419,531],{"class":434},[416,1421,1295],{"class":422},[416,1423,435],{"class":434},[416,1425,462],{"class":454},[416,1427,1409],{"class":458},[416,1429,462],{"class":454},[416,1431,1348],{"class":434},[416,1433,827],{"class":454},[416,1435,1436],{"class":458},"carrot",[416,1438,462],{"class":454},[416,1440,545],{"class":434},[395,1442,1443,1444,1447],{},"Reading a missing key gives a nil slice, which ",[413,1445,1446],{},"append"," handles happily, so no setup is needed.",[395,1449,1450],{},"One restriction catches people out: you cannot change a field of a struct stored in a map directly.",[406,1452,1454],{"className":408,"code":1453,"language":410,"meta":411,"style":411},"type Player struct{ Score int }\n\nplayers := map[string]Player{\"ada\": {Score: 1}}\nplayers[\"ada\"].Score = 10 \u002F\u002F compile error\n",[413,1455,1456,1479,1483,1525],{"__ignoreMap":411},[416,1457,1458,1461,1465,1468,1470,1473,1476],{"class":418,"line":419},[416,1459,1460],{"class":430},"type",[416,1462,1464],{"class":1463},"snwKR"," Player",[416,1466,1467],{"class":430}," struct",[416,1469,1070],{"class":434},[416,1471,1472],{"class":422}," Score",[416,1474,1475],{"class":438}," int",[416,1477,1478],{"class":434}," }\n",[416,1480,1481],{"class":418,"line":451},[416,1482,551],{"emptyLinePlaceholder":550},[416,1484,1485,1488,1490,1492,1494,1496,1498,1501,1503,1505,1508,1510,1512,1515,1518,1520,1522],{"class":418,"line":475},[416,1486,1487],{"class":422},"players",[416,1489,427],{"class":426},[416,1491,431],{"class":430},[416,1493,435],{"class":434},[416,1495,439],{"class":438},[416,1497,442],{"class":434},[416,1499,1500],{"class":1463},"Player",[416,1502,1070],{"class":434},[416,1504,462],{"class":454},[416,1506,1507],{"class":458},"ada",[416,1509,462],{"class":454},[416,1511,465],{"class":434},[416,1513,1514],{"class":434}," {",[416,1516,1517],{"class":422},"Score",[416,1519,465],{"class":434},[416,1521,1082],{"class":468},[416,1523,1524],{"class":434},"}}\n",[416,1526,1527,1529,1531,1533,1535,1537,1540,1542,1544,1546],{"class":418,"line":492},[416,1528,1487],{"class":422},[416,1530,435],{"class":434},[416,1532,462],{"class":454},[416,1534,1507],{"class":458},[416,1536,462],{"class":454},[416,1538,1539],{"class":434},"].",[416,1541,1517],{"class":422},[416,1543,569],{"class":426},[416,1545,572],{"class":468},[416,1547,1548],{"class":575}," \u002F\u002F compile error\n",[406,1550,1553],{"className":1551,"code":1552,"language":1251,"meta":411},[1249],"cannot assign to struct field players[\"ada\"].Score in map\n",[413,1554,1552],{"__ignoreMap":411},[395,1556,1557,1558,1561],{},"Read the value, change it, and store it back, or use a map of pointers (",[413,1559,1560],{},"map[string]*Player",").",[390,1563,1565],{"id":1564},"using-a-map-as-a-set","Using a map as a set",[395,1567,1568,1569,1572],{},"Go has no built-in set type. The usual stand-in is a map with ",[413,1570,1571],{},"bool"," or empty-struct values:",[406,1574,1576],{"className":408,"code":1575,"language":410,"meta":411,"style":411},"seen := make(map[string]bool)\nseen[\"go\"] = true\n\nif seen[\"go\"] {\n    fmt.Println(\"already seen go\")\n}\n",[413,1577,1578,1601,1621,1625,1644,1663],{"__ignoreMap":411},[416,1579,1580,1583,1585,1587,1589,1591,1593,1595,1597,1599],{"class":418,"line":419},[416,1581,1582],{"class":422},"seen",[416,1584,427],{"class":426},[416,1586,528],{"class":527},[416,1588,531],{"class":434},[416,1590,534],{"class":430},[416,1592,435],{"class":434},[416,1594,439],{"class":438},[416,1596,442],{"class":434},[416,1598,1571],{"class":438},[416,1600,545],{"class":434},[416,1602,1603,1605,1607,1609,1611,1613,1615,1617],{"class":418,"line":451},[416,1604,1582],{"class":422},[416,1606,435],{"class":434},[416,1608,462],{"class":454},[416,1610,410],{"class":458},[416,1612,462],{"class":454},[416,1614,442],{"class":434},[416,1616,569],{"class":426},[416,1618,1620],{"class":1619},"sqQ1y"," true\n",[416,1622,1623],{"class":418,"line":475},[416,1624,551],{"emptyLinePlaceholder":550},[416,1626,1627,1629,1632,1634,1636,1638,1640,1642],{"class":418,"line":492},[416,1628,730],{"class":729},[416,1630,1631],{"class":422}," seen",[416,1633,435],{"class":434},[416,1635,462],{"class":454},[416,1637,410],{"class":458},[416,1639,462],{"class":454},[416,1641,442],{"class":434},[416,1643,739],{"class":434},[416,1645,1646,1648,1650,1652,1654,1656,1659,1661],{"class":418,"line":599},[416,1647,744],{"class":422},[416,1649,625],{"class":434},[416,1651,665],{"class":527},[416,1653,531],{"class":434},[416,1655,462],{"class":454},[416,1657,1658],{"class":458},"already seen go",[416,1660,462],{"class":454},[416,1662,545],{"class":434},[416,1664,1665],{"class":418,"line":796},[416,1666,495],{"class":434},[395,1668,1669,1672,1673,1675],{},[413,1670,1671],{},"map[string]struct{}"," uses no memory for the values, but ",[413,1674,1571],{}," is easier to read for most programs.",[390,1677,1679],{"id":1678},"concurrency-warning","Concurrency warning",[395,1681,1682,1683,1686],{},"A map is not safe to read and write from several goroutines at the same time. Doing so can crash the program with ",[413,1684,1685],{},"fatal error: concurrent map writes",". Either keep the map inside one goroutine, protect it with a mutex, or use a structure designed for sharing. The concurrency stage covers this properly.",[390,1688,1690],{"id":1689},"common-mistakes","Common mistakes",[1692,1693,1694,1701,1707,1713,1718],"ul",{},[1695,1696,1697,1700],"li",{},[680,1698,1699],{},"Writing to a nil map."," Always create it first.",[1695,1702,1703,1706],{},[680,1704,1705],{},"Relying on iteration order."," Sort the keys when order matters.",[1695,1708,1709,1712],{},[680,1710,1711],{},"Using the zero value to detect absence."," Use the comma-ok form.",[1695,1714,1715],{},[680,1716,1717],{},"Expecting an assignment to copy the map.",[1695,1719,1720,1723],{},[680,1721,1722],{},"Trying to modify a struct field inside a map"," without storing the struct back.",[390,1725,1727],{"id":1726},"practice","Practice",[395,1729,1730,1731,625],{},"Count how often each word appears in a sentence. Then print the words and their counts in alphabetical order. Use the sentence ",[413,1732,1733],{},"\"go is fun go is fast go\"",[1735,1736,1737],"accordion",{},[1738,1739,1742,2066,2069,2075],"accordion-item",{"icon":1740,"label":1741},"i-lucide-lightbulb","Show solution",[406,1743,1745],{"className":408,"code":1744,"language":410,"meta":411,"style":411},"package main\n\nimport (\n    \"fmt\"\n    \"sort\"\n    \"strings\"\n)\n\nfunc main() {\n    sentence := \"go is fun go is fast go\"\n\n    counts := make(map[string]int)\n    for _, word := range strings.Fields(sentence) {\n        counts[word]++\n    }\n\n    words := make([]string, 0, len(counts))\n    for word := range counts {\n        words = append(words, word)\n    }\n    sort.Strings(words)\n\n    for _, word := range words {\n        fmt.Println(word, counts[word])\n    }\n}\n",[413,1746,1747,1755,1759,1767,1777,1785,1794,1798,1802,1815,1830,1835,1859,1893,1909,1915,1920,1949,1965,1986,1991,2007,2012,2032,2056,2061],{"__ignoreMap":411},[416,1748,1749,1752],{"class":418,"line":419},[416,1750,1751],{"class":430},"package",[416,1753,1754],{"class":1463}," main\n",[416,1756,1757],{"class":418,"line":451},[416,1758,551],{"emptyLinePlaceholder":550},[416,1760,1761,1764],{"class":418,"line":475},[416,1762,1763],{"class":729},"import",[416,1765,1766],{"class":434}," (\n",[416,1768,1769,1771,1774],{"class":418,"line":492},[416,1770,455],{"class":454},[416,1772,660],{"class":1773},"sdLNw",[416,1775,1776],{"class":454},"\"\n",[416,1778,1779,1781,1783],{"class":418,"line":599},[416,1780,455],{"class":454},[416,1782,972],{"class":1773},[416,1784,1776],{"class":454},[416,1786,1787,1789,1792],{"class":418,"line":796},[416,1788,455],{"class":454},[416,1790,1791],{"class":1773},"strings",[416,1793,1776],{"class":454},[416,1795,1796],{"class":418,"line":990},[416,1797,545],{"class":434},[416,1799,1800],{"class":418,"line":1011},[416,1801,551],{"emptyLinePlaceholder":550},[416,1803,1804,1807,1810,1813],{"class":418,"line":1036},[416,1805,1806],{"class":430},"func",[416,1808,1809],{"class":527}," main",[416,1811,1812],{"class":434},"()",[416,1814,739],{"class":434},[416,1816,1818,1821,1823,1825,1828],{"class":418,"line":1817},10,[416,1819,1820],{"class":422},"    sentence",[416,1822,427],{"class":426},[416,1824,827],{"class":454},[416,1826,1827],{"class":458},"go is fun go is fast go",[416,1829,1776],{"class":454},[416,1831,1833],{"class":418,"line":1832},11,[416,1834,551],{"emptyLinePlaceholder":550},[416,1836,1838,1841,1843,1845,1847,1849,1851,1853,1855,1857],{"class":418,"line":1837},12,[416,1839,1840],{"class":422},"    counts",[416,1842,427],{"class":426},[416,1844,528],{"class":527},[416,1846,531],{"class":434},[416,1848,534],{"class":430},[416,1850,435],{"class":434},[416,1852,439],{"class":438},[416,1854,442],{"class":434},[416,1856,445],{"class":438},[416,1858,545],{"class":434},[416,1860,1862,1865,1867,1869,1872,1874,1876,1879,1881,1884,1886,1889,1891],{"class":418,"line":1861},13,[416,1863,1864],{"class":729},"    for",[416,1866,995],{"class":422},[416,1868,706],{"class":434},[416,1870,1871],{"class":422}," word",[416,1873,427],{"class":426},[416,1875,862],{"class":729},[416,1877,1878],{"class":422}," strings",[416,1880,625],{"class":434},[416,1882,1883],{"class":527},"Fields",[416,1885,531],{"class":434},[416,1887,1888],{"class":422},"sentence",[416,1890,672],{"class":434},[416,1892,739],{"class":434},[416,1894,1896,1899,1901,1904,1906],{"class":418,"line":1895},14,[416,1897,1898],{"class":422},"        counts",[416,1900,435],{"class":434},[416,1902,1903],{"class":422},"word",[416,1905,442],{"class":434},[416,1907,1908],{"class":614},"++\n",[416,1910,1912],{"class":418,"line":1911},15,[416,1913,1914],{"class":434},"    }\n",[416,1916,1918],{"class":418,"line":1917},16,[416,1919,551],{"emptyLinePlaceholder":550},[416,1921,1923,1926,1928,1930,1932,1934,1936,1938,1940,1942,1944,1947],{"class":418,"line":1922},17,[416,1924,1925],{"class":422},"    words",[416,1927,427],{"class":426},[416,1929,528],{"class":527},[416,1931,909],{"class":434},[416,1933,439],{"class":438},[416,1935,706],{"class":434},[416,1937,916],{"class":468},[416,1939,706],{"class":434},[416,1941,921],{"class":527},[416,1943,531],{"class":434},[416,1945,1946],{"class":422},"counts",[416,1948,928],{"class":434},[416,1950,1952,1954,1956,1958,1960,1963],{"class":418,"line":1951},18,[416,1953,1864],{"class":729},[416,1955,1871],{"class":422},[416,1957,427],{"class":426},[416,1959,862],{"class":729},[416,1961,1962],{"class":422}," counts",[416,1964,739],{"class":434},[416,1966,1968,1971,1973,1975,1977,1980,1982,1984],{"class":418,"line":1967},19,[416,1969,1970],{"class":422},"        words",[416,1972,569],{"class":426},[416,1974,953],{"class":527},[416,1976,531],{"class":434},[416,1978,1979],{"class":422},"words",[416,1981,706],{"class":434},[416,1983,1871],{"class":422},[416,1985,545],{"class":434},[416,1987,1989],{"class":418,"line":1988},20,[416,1990,1914],{"class":434},[416,1992,1994,1997,1999,2001,2003,2005],{"class":418,"line":1993},21,[416,1995,1996],{"class":422},"    sort",[416,1998,625],{"class":434},[416,2000,977],{"class":527},[416,2002,531],{"class":434},[416,2004,1979],{"class":422},[416,2006,545],{"class":434},[416,2008,2010],{"class":418,"line":2009},22,[416,2011,551],{"emptyLinePlaceholder":550},[416,2013,2015,2017,2019,2021,2023,2025,2027,2030],{"class":418,"line":2014},23,[416,2016,1864],{"class":729},[416,2018,995],{"class":422},[416,2020,706],{"class":434},[416,2022,1871],{"class":422},[416,2024,427],{"class":426},[416,2026,862],{"class":729},[416,2028,2029],{"class":422}," words",[416,2031,739],{"class":434},[416,2033,2035,2038,2040,2042,2044,2046,2048,2050,2052,2054],{"class":418,"line":2034},24,[416,2036,2037],{"class":422},"        fmt",[416,2039,625],{"class":434},[416,2041,665],{"class":527},[416,2043,531],{"class":434},[416,2045,1903],{"class":422},[416,2047,706],{"class":434},[416,2049,1962],{"class":422},[416,2051,435],{"class":434},[416,2053,1903],{"class":422},[416,2055,1033],{"class":434},[416,2057,2059],{"class":418,"line":2058},25,[416,2060,1914],{"class":434},[416,2062,2064],{"class":418,"line":2063},26,[416,2065,495],{"class":434},[395,2067,2068],{},"Output:",[406,2070,2073],{"className":2071,"code":2072,"language":1251,"meta":411},[1249],"fast 1\nfun 1\ngo 3\nis 2\n",[413,2074,2072],{"__ignoreMap":411},[395,2076,2077,2080,2081,2084,2085,2087],{},[413,2078,2079],{},"strings.Fields"," splits the sentence into words. ",[413,2082,2083],{},"counts[word]++"," works even the first time because a missing key reads as ",[413,2086,686],{},", which is then increased to 1. Map iteration order is random, so the keys are copied into a slice and sorted before printing.",[390,2089,2091],{"id":2090},"summary","Summary",[395,2093,2094,2095,2098],{},"A map looks values up by key, with the type written ",[413,2096,2097],{},"map[KeyType]ValueType",". A missing key reads as the zero value, so use the comma-ok form when absence matters. Iteration order is unspecified, so sort the keys for stable output. Maps are shared when assigned, writing to a nil map panics, and ordinary maps are not safe for concurrent writes.",[395,2100,2101,2102,625],{},"Official reference: ",[1075,2103,2107],{"href":2104,"rel":2105},"https:\u002F\u002Fgo.dev\u002Fblog\u002Fmaps",[2106],"nofollow","Go maps in action",[2109,2110],"learning-lesson-complete",{},[2112,2113],"learning-lesson-navigation",{"next":51,"nextTitle":50,"previous":106,"previousTitle":105},[2115,2116,2117],"style",{},"html pre.shiki code .s45-6, html code.shiki .s45-6{--shiki-light:#268BD2;--shiki-default:#EEFFFF;--shiki-dark:#E06C75}html pre.shiki code .su2KV, html code.shiki .su2KV{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#E5C07B}html pre.shiki code .sEOdo, html code.shiki .sEOdo{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#C678DD}html pre.shiki code .shFME, html code.shiki .shFME{--shiki-light:#657B83;--shiki-default:#89DDFF;--shiki-dark:#ABB2BF}html pre.shiki code .sF6sA, html code.shiki .sF6sA{--shiki-light:#586E75;--shiki-light-font-weight:bold;--shiki-default:#C792EA;--shiki-default-font-weight:inherit;--shiki-dark:#C678DD;--shiki-dark-font-weight:inherit}html pre.shiki code .sED5a, html code.shiki .sED5a{--shiki-light:#2AA198;--shiki-default:#89DDFF;--shiki-dark:#98C379}html pre.shiki code .sVazx, html code.shiki .sVazx{--shiki-light:#2AA198;--shiki-default:#C3E88D;--shiki-dark:#98C379}html pre.shiki code .sAJzr, html code.shiki .sAJzr{--shiki-light:#D33682;--shiki-default:#F78C6C;--shiki-dark:#D19A66}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 .sisdC, html code.shiki .sisdC{--shiki-light:#268BD2;--shiki-default:#82AAFF;--shiki-dark:#61AFEF}html pre.shiki code .sJsHy, html code.shiki .sJsHy{--shiki-light:#93A1A1;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic}html pre.shiki code .sRBoR, html code.shiki .sRBoR{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#56B6C2}html pre.shiki code .s7Bcg, html code.shiki .s7Bcg{--shiki-light:#859900;--shiki-light-font-style:inherit;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#C678DD;--shiki-dark-font-style:inherit}html pre.shiki code .snwKR, html code.shiki .snwKR{--shiki-light:#CB4B16;--shiki-default:#FFCB6B;--shiki-dark:#E5C07B}html pre.shiki code .sqQ1y, html code.shiki .sqQ1y{--shiki-light:#B58900;--shiki-default:#FF9CAC;--shiki-dark:#D19A66}html pre.shiki code .sdLNw, html code.shiki .sdLNw{--shiki-light:#2AA198;--shiki-default:#FFCB6B;--shiki-dark:#98C379}",{"title":411,"searchDepth":451,"depth":451,"links":2119},[2120,2121,2122,2123,2124,2125,2126,2127,2128,2129,2130,2131,2132,2133,2134],{"id":392,"depth":451,"text":393},{"id":400,"depth":451,"text":401},{"id":505,"depth":451,"text":506},{"id":628,"depth":451,"text":629},{"id":807,"depth":451,"text":808},{"id":839,"depth":451,"text":840},{"id":1041,"depth":451,"text":1042},{"id":1157,"depth":451,"text":1158},{"id":1266,"depth":451,"text":1267},{"id":1281,"depth":451,"text":1282},{"id":1564,"depth":451,"text":1565},{"id":1678,"depth":451,"text":1679},{"id":1689,"depth":451,"text":1690},{"id":1726,"depth":451,"text":1727},{"id":2090,"depth":451,"text":2091},"Store key-value data, and safely read, update, delete, and iterate over maps.","md",null,{},{"icon":113},{"description":2141,"title":110},"Learn Go maps including creating and updating entries, the comma-ok lookup, deleting, unordered iteration, nil maps, valid key types, sets, and concurrency limits.","xyfHo6g5w2hetuEIshvjBeA9tWIUPz3Yn60C2pcuFV8",[2144,2146],{"title":105,"path":106,"stem":107,"description":2145,"icon":108,"children":-1},"Store ordered values with arrays and slices, and understand length, capacity, append, copy, and shared backing arrays.",{"title":120,"path":121,"stem":122,"description":2147,"icon":123,"children":-1},"Understand concurrency, parallelism, goroutines, coordination, and ownership before writing concurrent code.",1794118095488]