Skip to content

Instantly share code, notes, and snippets.

@PedroArSp
Created January 30, 2022 00:49
Show Gist options
  • Select an option

  • Save PedroArSp/467ac0a8207c3b7919d61596f745241d to your computer and use it in GitHub Desktop.

Select an option

Save PedroArSp/467ac0a8207c3b7919d61596f745241d to your computer and use it in GitHub Desktop.
python case incensitive / accent incensitive compare
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"source": "# Python doing a string case insensitive and accent incensivite compare",
"metadata": {
"cell_id": "b4d53eae-f6cc-4e8c-83bb-7786fb8a8782",
"tags": [],
"deepnote_app_coordinates": {
"x": 0,
"y": 24,
"w": 12,
"h": 10
},
"deepnote_cell_type": "markdown"
}
},
{
"cell_type": "markdown",
"source": "## Using unidecode module (3rd Party) and str.casefold()\n__$pip install unidecode__",
"metadata": {
"cell_id": "b69598ad-7f14-4958-93f4-d95dfce15672",
"tags": [],
"deepnote_app_coordinates": {
"x": 0,
"y": 35,
"w": 12,
"h": 9
},
"deepnote_cell_type": "markdown"
}
},
{
"cell_type": "code",
"metadata": {
"cell_id": "43fd25e5-eae2-48f6-8195-00e5d710d222",
"tags": [],
"deepnote_to_be_reexecuted": false,
"source_hash": "2ebe3928",
"execution_start": 1643410298357,
"execution_millis": 4,
"deepnote_app_coordinates": {
"x": 0,
"y": null,
"w": 12,
"h": 5
},
"deepnote_cell_type": "code"
},
"source": "from unidecode import unidecode",
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"cell_id": "eaff3991-570e-4acf-9115-daf14d5a8576",
"tags": [],
"deepnote_to_be_reexecuted": false,
"source_hash": "1b9883ed",
"execution_start": 1643410298365,
"execution_millis": 3,
"deepnote_app_coordinates": {
"x": 0,
"y": 6,
"w": 12,
"h": 5
},
"deepnote_cell_type": "code"
},
"source": "def normString(text:str)->str:\n if isinstance(text,str):\n return unidecode(text).casefold()\n else:\n return text",
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"cell_id": "b70ba0d0-644b-46a4-a9c1-5216f6b4fc7d",
"tags": [],
"deepnote_to_be_reexecuted": false,
"source_hash": "dc240c12",
"execution_start": 1643410298371,
"execution_millis": 224,
"deepnote_output_heights": [
1
],
"deepnote_app_coordinates": {
"x": 0,
"y": 12,
"w": 12,
"h": 5
},
"deepnote_cell_type": "code"
},
"source": "normString('Pedro Andrés Riva')",
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 4,
"data": {
"text/plain": "'pedro andres riva'"
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"metadata": {
"cell_id": "2a40f002-0983-44d7-8db0-2792fc65d771",
"tags": [],
"deepnote_to_be_reexecuted": false,
"source_hash": "71212a6e",
"execution_start": 1643410298383,
"execution_millis": 213,
"deepnote_output_heights": [
1
],
"deepnote_app_coordinates": {
"x": 0,
"y": 18,
"w": 12,
"h": 5
},
"deepnote_cell_type": "code"
},
"source": "normString('Pedro Andrés Riva') == normString('pedro andres riva')",
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 5,
"data": {
"text/plain": "True"
},
"metadata": {}
}
]
},
{
"cell_type": "markdown",
"source": "<a style='text-decoration:none;line-height:16px;display:flex;color:#5B5B62;padding:10px;justify-content:end;' href='https://deepnote.com?utm_source=created-in-deepnote-cell&projectId=053a5b31-dbff-4d45-83ed-9b84b2157307' target=\"_blank\">\n<img alt='Created in deepnote.com' style='display:inline;max-height:16px;margin:0px;margin-right:7.5px;' src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iODBweCIgaGVpZ2h0PSI4MHB4IiB2aWV3Qm94PSIwIDAgODAgODAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8IS0tIEdlbmVyYXRvcjogU2tldGNoIDU0L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ODk5LDc3LjM3NjE0NCBMMzUuMDA3NzE4LDgwIFoiIGlkPSJQYXRoLTIyIiBmaWxsPSIjMDAyODY4Ij48L3BhdGg+CiAgICAgICAgICAgICAgICA8cGF0aCBkPSJNMCwzNy43MzA0NDA1IEwyNy4xMTQ1MzcsMC4yNTcxMTE0MzYgQzYyLjM3MTUxMjMsLTEuOTkwNzE3MDEgODAsMTAuNTAwMzkyNyA4MCwzNy43MzA0NDA1IEM4MCw2NC45NjA0ODgyIDY0Ljc3NjUwMzgsNzkuMDUwMzQxNCAzNC4zMjk1MTEzLDgwIEM0Ny4wNTUzNDg5LDc3LjU2NzA4MDggNTMuNDE4MjY3Nyw3MC4zMTM2MTAzIDUzLjQxODI2NzcsNTguMjM5NTg4NSBDNTMuNDE4MjY3Nyw0MC4xMjg1NTU3IDM2LjMwMzk1NDQsMzcuNzMwNDQwNSAyNS4yMjc0MTcsMzcuNzMwNDQwNSBDMTcuODQzMDU4NiwzNy43MzA0NDA1IDkuNDMzOTE5NjYsMzcuNzMwNDQwNSAwLDM3LjczMDQ0MDUgWiIgaWQ9IlBhdGgtMTkiIGZpbGw9IiMzNzkzRUYiPjwvcGF0aD4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+' > </img>\nCreated in <span style='font-weight:600;margin-left:4px;'>Deepnote</span></a>",
"metadata": {
"tags": [],
"created_in_deepnote_cell": true,
"deepnote_cell_type": "markdown"
}
}
],
"nbformat": 4,
"nbformat_minor": 2,
"metadata": {
"orig_nbformat": 2,
"deepnote": {
"is_reactive": false
},
"deepnote_notebook_id": "943cccdf-1ffc-4a20-8209-df33a7fcb348",
"deepnote_execution_queue": [],
"deepnote_app_layout": "article"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment