Skip to content

Commit

Permalink
sets
Browse files Browse the repository at this point in the history
  • Loading branch information
luigiselmi committed May 29, 2024
1 parent b7b0854 commit f5185f6
Showing 1 changed file with 76 additions and 2 deletions.
78 changes: 76 additions & 2 deletions python/scipy-numpy-cheat-sheet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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": {},
Expand Down

0 comments on commit f5185f6

Please sign in to comment.