|
324 | 324 | } |
325 | 325 | ] |
326 | 326 | }, |
| 327 | + { |
| 328 | + "cell_type": "code", |
| 329 | + "source": [ |
| 330 | + "repeating_list: list = []\n", |
| 331 | + "\n", |
| 332 | + "def repeat_n(numbers: list) -> None:\n", |
| 333 | + " for n in numbers:\n", |
| 334 | + " if (n == n+1):\n", |
| 335 | + " repeating_list.append(n)\n", |
| 336 | + " else: print('no repeatation')\n", |
| 337 | + "\n", |
| 338 | + "repeat_n([1, 2 , 3 ,4 ,5 , 4 ,2])" |
| 339 | + ], |
| 340 | + "metadata": { |
| 341 | + "colab": { |
| 342 | + "base_uri": "https://localhost:8080/" |
| 343 | + }, |
| 344 | + "id": "rEXmyQ4otUzj", |
| 345 | + "outputId": "fdb4996d-d5a1-4216-d6a5-c02614a6579e" |
| 346 | + }, |
| 347 | + "execution_count": 2, |
| 348 | + "outputs": [ |
| 349 | + { |
| 350 | + "output_type": "stream", |
| 351 | + "name": "stdout", |
| 352 | + "text": [ |
| 353 | + "no repeatation\n", |
| 354 | + "no repeatation\n", |
| 355 | + "no repeatation\n", |
| 356 | + "no repeatation\n", |
| 357 | + "no repeatation\n", |
| 358 | + "no repeatation\n", |
| 359 | + "no repeatation\n" |
| 360 | + ] |
| 361 | + } |
| 362 | + ] |
| 363 | + }, |
| 364 | + { |
| 365 | + "cell_type": "code", |
| 366 | + "source": [ |
| 367 | + "rep_list: list = []\n", |
| 368 | + "\n", |
| 369 | + "def fn_list(numbers: list):\n", |
| 370 | + " for n in numbers:\n", |
| 371 | + " if (n + 1 == n) & (n == n+1):\n", |
| 372 | + " rep_list.append(n)\n", |
| 373 | + " print('repeating!')\n", |
| 374 | + " else: print('No repeating')\n", |
| 375 | + "\n", |
| 376 | + "\n", |
| 377 | + "print(rep_list)\n", |
| 378 | + "\n", |
| 379 | + "fn_list([1 , 2 , 3 , 4 , 5 , 2 ,3])\n", |
| 380 | + "fn_list([6 , 7 , 1 , 4 , 7])" |
| 381 | + ], |
| 382 | + "metadata": { |
| 383 | + "colab": { |
| 384 | + "base_uri": "https://localhost:8080/" |
| 385 | + }, |
| 386 | + "id": "fftokFA2a93W", |
| 387 | + "outputId": "d9303613-5903-4f64-fbc0-3a3193ecfa8c" |
| 388 | + }, |
| 389 | + "execution_count": 14, |
| 390 | + "outputs": [ |
| 391 | + { |
| 392 | + "output_type": "stream", |
| 393 | + "name": "stdout", |
| 394 | + "text": [ |
| 395 | + "[]\n", |
| 396 | + "No repeating\n", |
| 397 | + "No repeating\n", |
| 398 | + "No repeating\n", |
| 399 | + "No repeating\n", |
| 400 | + "No repeating\n", |
| 401 | + "No repeating\n", |
| 402 | + "No repeating\n", |
| 403 | + "No repeating\n", |
| 404 | + "No repeating\n", |
| 405 | + "No repeating\n", |
| 406 | + "No repeating\n", |
| 407 | + "No repeating\n" |
| 408 | + ] |
| 409 | + } |
| 410 | + ] |
| 411 | + }, |
| 412 | + { |
| 413 | + "cell_type": "code", |
| 414 | + "source": [ |
| 415 | + "def find_first_repeat(numbers: list):\n", |
| 416 | + " seen_ = set()\n", |
| 417 | + " for n in numbers:\n", |
| 418 | + " if (n in seen_):\n", |
| 419 | + " return n\n", |
| 420 | + " seen_.add(n)\n", |
| 421 | + " return 'No repeating'" |
| 422 | + ], |
| 423 | + "metadata": { |
| 424 | + "id": "r9EbVHzPbePF" |
| 425 | + }, |
| 426 | + "execution_count": 15, |
| 427 | + "outputs": [] |
| 428 | + }, |
| 429 | + { |
| 430 | + "cell_type": "code", |
| 431 | + "source": [ |
| 432 | + "print(find_first_repeat([1, 2, 3, 4, 5, 2, 3]))" |
| 433 | + ], |
| 434 | + "metadata": { |
| 435 | + "colab": { |
| 436 | + "base_uri": "https://localhost:8080/" |
| 437 | + }, |
| 438 | + "id": "1EfJ3m50x9hL", |
| 439 | + "outputId": "b96052fb-5fc0-4822-bb88-d63b5295a392" |
| 440 | + }, |
| 441 | + "execution_count": 16, |
| 442 | + "outputs": [ |
| 443 | + { |
| 444 | + "output_type": "stream", |
| 445 | + "name": "stdout", |
| 446 | + "text": [ |
| 447 | + "2\n" |
| 448 | + ] |
| 449 | + } |
| 450 | + ] |
| 451 | + }, |
| 452 | + { |
| 453 | + "cell_type": "code", |
| 454 | + "source": [ |
| 455 | + "def find_first_repeat(numbers: list) -> None:\n", |
| 456 | + " try:\n", |
| 457 | + " seen = set()\n", |
| 458 | + "\n", |
| 459 | + " for n in numbers:\n", |
| 460 | + " if n in seen:\n", |
| 461 | + " return n\n", |
| 462 | + " seen.append(n)\n", |
| 463 | + " return 'No repeat!'\n", |
| 464 | + "\n", |
| 465 | + " except TypeError:\n", |
| 466 | + " return 'Invalid input: Please pass a list of numbers'\n", |
| 467 | + "" |
| 468 | + ], |
| 469 | + "metadata": { |
| 470 | + "id": "g8iyZuulyhY1" |
| 471 | + }, |
| 472 | + "execution_count": 17, |
| 473 | + "outputs": [] |
| 474 | + }, |
| 475 | + { |
| 476 | + "cell_type": "code", |
| 477 | + "source": [ |
| 478 | + "def most_frequent(numbers: list) -> int:\n", |
| 479 | + " dic_count: dict = {}\n", |
| 480 | + " for n in numbers:\n", |
| 481 | + " if n in dic_count:\n", |
| 482 | + " dic_count[n] += 1\n", |
| 483 | + " else:\n", |
| 484 | + " dic_count[n] = 1\n", |
| 485 | + "\n", |
| 486 | + " most_frequent()" |
| 487 | + ], |
| 488 | + "metadata": { |
| 489 | + "id": "i3Ml9aKy5pAK" |
| 490 | + }, |
| 491 | + "execution_count": 18, |
| 492 | + "outputs": [] |
| 493 | + }, |
| 494 | + { |
| 495 | + "cell_type": "code", |
| 496 | + "source": [], |
| 497 | + "metadata": { |
| 498 | + "id": "7dbIWCM67kQi" |
| 499 | + }, |
| 500 | + "execution_count": 32, |
| 501 | + "outputs": [] |
| 502 | + }, |
| 503 | + { |
| 504 | + "cell_type": "code", |
| 505 | + "source": [], |
| 506 | + "metadata": { |
| 507 | + "id": "vEcUfxT075jW" |
| 508 | + }, |
| 509 | + "execution_count": 32, |
| 510 | + "outputs": [] |
| 511 | + }, |
| 512 | + { |
| 513 | + "cell_type": "code", |
| 514 | + "source": [], |
| 515 | + "metadata": { |
| 516 | + "id": "UmOTNRQD75lW" |
| 517 | + }, |
| 518 | + "execution_count": 32, |
| 519 | + "outputs": [] |
| 520 | + }, |
| 521 | + { |
| 522 | + "cell_type": "code", |
| 523 | + "source": [], |
| 524 | + "metadata": { |
| 525 | + "id": "wSd5e2d_75nZ" |
| 526 | + }, |
| 527 | + "execution_count": null, |
| 528 | + "outputs": [] |
| 529 | + }, |
| 530 | + { |
| 531 | + "cell_type": "code", |
| 532 | + "source": [], |
| 533 | + "metadata": { |
| 534 | + "id": "D-ZPAwKi7kS0" |
| 535 | + }, |
| 536 | + "execution_count": null, |
| 537 | + "outputs": [] |
| 538 | + }, |
| 539 | + { |
| 540 | + "cell_type": "code", |
| 541 | + "source": [], |
| 542 | + "metadata": { |
| 543 | + "id": "q59IHbbo7BEa" |
| 544 | + }, |
| 545 | + "execution_count": 18, |
| 546 | + "outputs": [] |
| 547 | + }, |
327 | 548 | { |
328 | 549 | "cell_type": "code", |
329 | 550 | "source": [], |
330 | 551 | "metadata": { |
331 | | - "id": "rEXmyQ4otUzj" |
| 552 | + "id": "qPnQ_N5E7BGc" |
332 | 553 | }, |
333 | 554 | "execution_count": null, |
334 | 555 | "outputs": [] |
|
0 commit comments