{"componentChunkName":"component---node-modules-smooth-doc-src-templates-doc-js","path":"/docs/dictcomps/","result":{"data":{"mdx":{"fields":{"pageType":"doc","title":"Dictionary Comprehension","editLink":""},"body":"var _excluded = [\"components\"];\nfunction _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n/* @jsxRuntime classic */\n/* @jsx mdx */\n\nvar _frontmatter = {\n  \"title\": \"Dictionary Comprehension\",\n  \"section\": \"Quick Docs\",\n  \"order\": 9\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n    props = _objectWithoutProperties(_ref, _excluded);\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"Dictionary comprehensions (\", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"dict comps\"), \") provide a convenient way to make dictionaries, just like list comps:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-py\"\n  }, \">>> {word.lower(): len(word) for word in ('I', 'love', 'Python')}\\n{'i': 1, 'love': 4, 'python': 6}\\n\")), mdx(\"p\", null, \"The syntax is very similar to list comps except that you surround it with curly braces and have two expressions: one for the key and one for the value.\"), mdx(\"p\", null, \"One can use a dict comp to change an existing dictionary using its \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"items\"), \" method\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-py\"\n  }, \">>> first_dict = {'i': 1, 'love': 4, 'python': 6}\\n>>> {key.upper(): value * 2 for key, value in first_dict.items()}\\n{'I': 2, 'LOVE': 8, 'PYTHON': 12}\\n\")), mdx(\"p\", null, \"For more information and examples, check out \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://peps.python.org/pep-0274/\"\n  }, \"PEP 274\")));\n}\n;\nMDXContent.isMDXComponent = true;","tableOfContents":{}}},"pageContext":{"id":"b734bc73-6cca-5b64-941b-602a7fbb1a5d"}},"staticQueryHashes":["1022386572","1122327541","1339625561","2140385554","3442269102","3597609067"]}