|
32 | 32 | "cell_type": "markdown",
|
33 | 33 | "metadata": {},
|
34 | 34 | "source": [
|
35 |
| - "### Checking for PEP-8 errors\n", |
| 35 | + "#### Checking for PEP-8 errors\n", |
36 | 36 | "\n",
|
37 | 37 | " import pycodestyle\n",
|
38 | 38 | "\n",
|
|
84 | 84 | "cell_type": "markdown",
|
85 | 85 | "metadata": {},
|
86 | 86 | "source": [
|
87 |
| - "### Help function\n", |
| 87 | + "#### Help function\n", |
88 | 88 | "\n",
|
89 | 89 | "Using before just about anything in the parentheses will bring up useful information on that call\n",
|
90 | 90 | "\n",
|
|
481 | 481 | "- return (data)"
|
482 | 482 | ]
|
483 | 483 | },
|
| 484 | + { |
| 485 | + "cell_type": "markdown", |
| 486 | + "metadata": {}, |
| 487 | + "source": [ |
| 488 | + "#### Recursive Functions\n", |
| 489 | + "Recursion is a way of programming or coding a problem, in which a function calls itself one or more times in its body. Usually, it is returning the return value of this function call. If a function definition fulfills the condition of recursion, we call this function a recursive function.\n", |
| 490 | + "\n", |
| 491 | + "Termination condition:\n", |
| 492 | + "A recursive function has to terminate to be used in a program. A recursive function terminates, if with every recursive call the solution of the problem is downsized and moves towards a base case. A base case is a case, where the problem can be solved without further recursion. A recursion can lead to an infinite loop, if the base case is not met in the calls.\n", |
| 493 | + "\n", |
| 494 | + "##### Fibonacci Sequence\n", |
| 495 | + " def fib(n):\n", |
| 496 | + " if n < 1:\n", |
| 497 | + " return \"N must be an integer greater then 1\" #will notify that positive integer is needed\n", |
| 498 | + " elif n in [1,2]:\n", |
| 499 | + " return 1 #since addition of first two elements differs from the rest, need the elif statement\n", |
| 500 | + " else:\n", |
| 501 | + " return fib(n-1) + fib(n-2) #recursive part that takes the number provided, and returns the proper calculation\n", |
| 502 | + " \n", |
| 503 | + " for i in range(1, 10):\n", |
| 504 | + " print(fib(i))\n", |
| 505 | + " \n", |
| 506 | + "##### Flatten a List \n", |
| 507 | + " def flat_list(L, result=[]):\n", |
| 508 | + " print('Current L:', L) #Optional, to display process\n", |
| 509 | + " for i in L:\n", |
| 510 | + " if type(i) == list:\n", |
| 511 | + " flat_list(i, result)\n", |
| 512 | + " else:\n", |
| 513 | + " result.append(i)\n", |
| 514 | + " return result" |
| 515 | + ] |
| 516 | + }, |
484 | 517 | {
|
485 | 518 | "cell_type": "markdown",
|
486 | 519 | "metadata": {},
|
|
542 | 575 | "source": [
|
543 | 576 | "#### Regular Expressions\n",
|
544 | 577 | "- import re - Import the Regular Expressions module\n",
|
545 |
| - "- re.search(r\"abc\",string) - Returns a match object if the regex \"abc\" is found in s, otherwise None\n", |
| 578 | + "- re.search(r\"abc\",string) - Returns a match object if the regex \"abc\" is found in string, otherwise None\n", |
546 | 579 | "- re.match(r\"abc\",string) - same as search, but is specific\n",
|
547 | 580 | "- re.split(r'dilimiter',string) - splits string by delimiter provided\n",
|
548 | 581 | "- re.sub(r\"abc\",\"xyz\",string) - Returns a string where all instances matching regex \"abc\" are replaced by \"xyz\"\n",
|
|
581 | 614 | " notmatch_tag = re.match(r\"<(\\w+)>\", string)\n",
|
582 | 615 | " #Print the first group capture\n",
|
583 | 616 | " print(\"Close your {} tag!\".format(notmatch_tag.group(1)))\n",
|
584 |
| - "##### lookaround\n", |
| 617 | + "##### lookaround\n", |
585 | 618 | "- regex(?=reference) = lookup word before the reference\n",
|
586 | 619 | "- regex(?!reference) = avoid looking up the word before reference\n",
|
587 | 620 | "- (?<=reference)regex = lookup word after the reference\n",
|
|
705 | 738 | "name": "python",
|
706 | 739 | "nbconvert_exporter": "python",
|
707 | 740 | "pygments_lexer": "ipython3",
|
708 |
| - "version": "3.7.4" |
| 741 | + "version": "3.7.5" |
709 | 742 | },
|
710 | 743 | "toc": {
|
711 | 744 | "base_numbering": 1,
|
|
0 commit comments