Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,232 @@
}
]
},
{
"cell_type": "code",
"source": [
"repeating_list: list = []\n",
"\n",
"def repeat_n(numbers: list) -> None:\n",
" for n in numbers:\n",
" if (n == n+1):\n",
" repeating_list.append(n)\n",
" else: print('no repeatation')\n",
"\n",
"repeat_n([1, 2 , 3 ,4 ,5 , 4 ,2])"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "rEXmyQ4otUzj",
"outputId": "fdb4996d-d5a1-4216-d6a5-c02614a6579e"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"no repeatation\n",
"no repeatation\n",
"no repeatation\n",
"no repeatation\n",
"no repeatation\n",
"no repeatation\n",
"no repeatation\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"rep_list: list = []\n",
"\n",
"def fn_list(numbers: list):\n",
" for n in numbers:\n",
" if (n + 1 == n) & (n == n+1):\n",
" rep_list.append(n)\n",
" print('repeating!')\n",
" else: print('No repeating')\n",
"\n",
"\n",
"print(rep_list)\n",
"\n",
"fn_list([1 , 2 , 3 , 4 , 5 , 2 ,3])\n",
"fn_list([6 , 7 , 1 , 4 , 7])"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "fftokFA2a93W",
"outputId": "d9303613-5903-4f64-fbc0-3a3193ecfa8c"
},
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[]\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n",
"No repeating\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"def find_first_repeat(numbers: list):\n",
" seen_ = set()\n",
" for n in numbers:\n",
" if (n in seen_):\n",
" return n\n",
" seen_.add(n)\n",
" return 'No repeating'"
],
"metadata": {
"id": "r9EbVHzPbePF"
},
"execution_count": 15,
"outputs": []
},
{
"cell_type": "code",
"source": [
"print(find_first_repeat([1, 2, 3, 4, 5, 2, 3]))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "1EfJ3m50x9hL",
"outputId": "b96052fb-5fc0-4822-bb88-d63b5295a392"
},
"execution_count": 16,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"2\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"def find_first_repeat(numbers: list) -> None:\n",
" try:\n",
" seen = set()\n",
"\n",
" for n in numbers:\n",
" if n in seen:\n",
" return n\n",
" seen.append(n)\n",
" return 'No repeat!'\n",
"\n",
" except TypeError:\n",
" return 'Invalid input: Please pass a list of numbers'\n",
""
],
"metadata": {
"id": "g8iyZuulyhY1"
},
"execution_count": 17,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def most_frequent(numbers: list) -> int:\n",
" dic_count: dict = {}\n",
" for n in numbers:\n",
" if n in dic_count:\n",
" dic_count[n] += 1\n",
" else:\n",
" dic_count[n] = 1\n",
"\n",
" most_frequent()"
],
"metadata": {
"id": "i3Ml9aKy5pAK"
},
"execution_count": 18,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "7dbIWCM67kQi"
},
"execution_count": 32,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "vEcUfxT075jW"
},
"execution_count": 32,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "UmOTNRQD75lW"
},
"execution_count": 32,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "wSd5e2d_75nZ"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "D-ZPAwKi7kS0"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "q59IHbbo7BEa"
},
"execution_count": 18,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "rEXmyQ4otUzj"
"id": "qPnQ_N5E7BGc"
},
"execution_count": null,
"outputs": []
Expand Down