Skip to content

Commit

Permalink
add caseinsensitivedicts
Browse files Browse the repository at this point in the history
  • Loading branch information
baniasbaabe committed Aug 10, 2024
1 parent 1a0f03f commit 74452b0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions book/pythontricks/utility.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,45 @@
"my_func()\n",
"# UnsupportedWarning: my_func is unsupported as of 1.0. Use my_func2 instead"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Case Insensitive Dictionaries"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Are you annoyed by case-sensitive dictionaries in Python?\n",
"\n",
"Try 𝐂𝐚𝐬𝐞𝐈𝐧𝐬𝐞𝐧𝐬𝐢𝐭𝐢𝐯𝐞𝐃𝐢𝐜𝐭𝐬.\n",
"\n",
"As the name says, you can access values by the key without paying attention to lowercase or uppercase.\n",
"\n",
"It's useful for everyone who is scraping API data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from requests.structures import CaseInsensitiveDict\n",
"\n",
"data: dict[str, str | int] = CaseInsensitiveDict(\n",
" {\n",
" \"accept\": \"application/json\",\n",
" \"content-type\": \"application/json\",\n",
" \"User-Agent\": \"Mozilla/5.0\",\n",
" }\n",
")\n",
"\n",
"print(data.get(\"Accept\"))"
]
}
],
"metadata": {
Expand Down

0 comments on commit 74452b0

Please sign in to comment.