diff --git a/python/scipy-numpy-cheat-sheet.ipynb b/python/scipy-numpy-cheat-sheet.ipynb index 5baab9d..151d9c9 100755 --- a/python/scipy-numpy-cheat-sheet.ipynb +++ b/python/scipy-numpy-cheat-sheet.ipynb @@ -31,12 +31,12 @@ "metadata": {}, "source": [ "### Tuple\n", - "A tutple is an immutable collection of immutable items that can be of different types: int, float, bool, string. A tuple provides few operators such as count() and index()" + "A tutple is an immutable collection of mutable or immutable items that can be of different types: int, float, bool, string. A tuple provides few operators such as count() and index()" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -56,6 +56,80 @@ "print(\"Number of occurrences: {0:d}\\nIndex of 1st occurrence: {1:d}\\n\".format(c, i))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Set\n", + "A set in Python is a mutable unordered collection of unique values. Several operation can be performed on sets, for instance union and intersection" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "s1 = {1, 2, 3, 'a', 'b'}\n", + "s2 = {'Rome', 'Paris', 1, 3}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Union of two sets" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3, 'Paris', 'Rome', 'a', 'b'}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s3 = s1 | s2\n", + "s3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Intersection of two sets" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 3}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s4 = s1 & s2\n", + "s4" + ] + }, { "cell_type": "markdown", "metadata": {},