Skip to content

Commit

Permalink
find an item in a list
Browse files Browse the repository at this point in the history
  • Loading branch information
luigiselmi committed May 10, 2024
1 parent d01c8e9 commit 8a40f05
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion python/scipy-numpy-cheat-sheet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,55 @@
"alist[2:4]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can look for an item in a list of strings"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"cities = ['Rome', 'Paris', 'London', 'Berlin', 'Madrid', 'Athens']"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"def find_item(list, item):\n",
" if (item in list):\n",
" return 1\n",
" else:\n",
" return 0"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"find_item(cities, 'Madrid')"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -2576,7 +2625,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 8a40f05

Please sign in to comment.