diff --git a/python/scipy-numpy-cheat-sheet.ipynb b/python/scipy-numpy-cheat-sheet.ipynb index df51c1d..5baab9d 100755 --- a/python/scipy-numpy-cheat-sheet.ipynb +++ b/python/scipy-numpy-cheat-sheet.ipynb @@ -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": {}, @@ -2576,7 +2625,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.11.5" } }, "nbformat": 4,