├── .gitignore ├── README.md ├── advanced ├── 02_deque.ipynb ├── 03_ordered_dictionary.ipynb ├── 04_default_dict.ipynb ├── 05_chained_map.ipynb ├── 06_pydantic.ipynb └── Screen Recording 2022-12-15 at 4.34.55 PM.mov ├── basics ├── OOP_In_Python.ipynb ├── async_example.py ├── closures.ipynb ├── list.md ├── merge_lists.py └── sets.ipynb ├── dsa ├── README.md ├── binary_search.ipynb └── binary_search_tree.ipynb ├── image-processing ├── blur_faces.ipynb ├── edge_detection.ipynb ├── faces.jpg ├── girls.jpeg ├── girls.png ├── group_image.jpg ├── image.ipynb ├── image_processing.ipynb ├── nn.png ├── noise_image.png ├── people.jpeg ├── puppy.png ├── rrr.png └── utils.py ├── interesting ├── ipyvizzu.ipynb ├── maplibre.ipynb ├── pydata.ipynb └── tryleap.ipynb ├── ml-apps ├── AA_wordsearch.ipynb ├── flip-image │ ├── README.md │ └── app.py ├── monster.ipynb ├── oneai │ ├── htmltosummary.py │ └── htmltotext.py └── tryleap.ipynb ├── oneAI └── oneapi_config.py ├── quizzes ├── 1_magic_methods.MD └── README.md ├── resources ├── cheat-sheets │ └── python.md ├── cheatsheets.md └── index.md ├── streamlit_apps └── 101 │ ├── README.md │ └── app.py ├── tips ├── audio_book.mp3 ├── first.png ├── py_notes.ipynb ├── python_100_programs.ipynb ├── python_tips.ipynb ├── python_tricks.ipynb └── test_data │ └── example.pdf └── webscrapping ├── quotes.csv ├── quotes.ipynb └── scrapper.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | config.py 9 | 10 | # Distribution / packaging 11 | .Python 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | pip-wheel-metadata/ 25 | share/python-wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | MANIFEST 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .nox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | *.py,cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | db.sqlite3 63 | db.sqlite3-journal 64 | 65 | # Flask stuff: 66 | instance/ 67 | .webassets-cache 68 | 69 | # Scrapy stuff: 70 | .scrapy 71 | 72 | # Sphinx documentation 73 | docs/_build/ 74 | 75 | # PyBuilder 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | .python-version 87 | 88 | # pipenv 89 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 90 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 91 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 92 | # install all needed dependencies. 93 | #Pipfile.lock 94 | 95 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 96 | __pypackages__/ 97 | 98 | # Celery stuff 99 | celerybeat-schedule 100 | celerybeat.pid 101 | 102 | # SageMath parsed files 103 | *.sage.py 104 | 105 | # Environments 106 | .env 107 | .venv 108 | env/ 109 | venv/ 110 | ENV/ 111 | env.bak/ 112 | venv.bak/ 113 | 114 | # Spyder project settings 115 | .spyderproject 116 | .spyproject 117 | 118 | # Rope project settings 119 | .ropeproject 120 | 121 | # mkdocs documentation 122 | /site 123 | 124 | # mypy 125 | .mypy_cache/ 126 | .dmypy.json 127 | dmypy.json 128 | 129 | # Pyre type checker 130 | .pyre/ 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Notes 2 | 3 | - This repo contains all the Python and ML Tutorials I share on twitter and YouTube. 4 | - Star this repo, if you don't want to miss any update. ⭐️ 5 | 6 | 7 | ## Advanced Python 8 | - [`deque`](advanced/02_deque.ipynb) 9 | 10 | ## Image Processing in Python 11 | - [`Edge Detection`](image-processing/edge_detection.ipynb) 12 | - [`Face Detection`](image-processing/image_processing.ipynb) 13 | - [`Blur Faces`](image-processing/blur_faces.ipynb) 14 | 15 | ## Interesting Libraries 16 | - [`Access datasets from Python`](interesting/pydata.ipynb) 17 | - [`Animations for Python Charts(ipyvizzu)`](interesting/ipyvizzu.ipynb) 18 | -------------------------------------------------------------------------------- /advanced/02_deque.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"attachments":{},"cell_type":"markdown","metadata":{},"source":["### `deque` in Python\n","\n","`deque` is double ended queue, which supports append and pop elements at both the ends. `deque` is implemented using doulbe linked list, which is very efficient for insert and delete elements at O(1)."]},{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[],"source":["from collections import deque"]},{"cell_type":"code","execution_count":2,"metadata":{},"outputs":[{"data":{"text/plain":["deque([])"]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["empty_deque = deque()\n","empty_deque"]},{"cell_type":"code","execution_count":5,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["deque([3, 5, 7, 11])\n"]}],"source":["# deque with elements\n","prime_numbers = deque([3,5,7,11])\n","print(prime_numbers)"]},{"cell_type":"code","execution_count":6,"metadata":{},"outputs":[{"data":{"text/plain":["deque([3, 5, 7, 11, 13])"]},"execution_count":6,"metadata":{},"output_type":"execute_result"}],"source":["# Append elements at the right end\n","prime_numbers.append(13)\n","prime_numbers"]},{"cell_type":"code","execution_count":7,"metadata":{},"outputs":[{"data":{"text/plain":["deque([2, 3, 5, 7, 11, 13])"]},"execution_count":7,"metadata":{},"output_type":"execute_result"}],"source":["# Append element at the left end\n","prime_numbers.appendleft(2)\n","prime_numbers"]},{"cell_type":"code","execution_count":8,"metadata":{},"outputs":[{"data":{"text/plain":["13"]},"execution_count":8,"metadata":{},"output_type":"execute_result"}],"source":["# pop element from the right end\n","prime_numbers.pop()"]},{"cell_type":"code","execution_count":10,"metadata":{},"outputs":[{"data":{"text/plain":["2"]},"execution_count":10,"metadata":{},"output_type":"execute_result"}],"source":["# pop element from the left end\n","prime_numbers.popleft()"]},{"cell_type":"code","execution_count":11,"metadata":{},"outputs":[{"data":{"text/plain":["deque([3, 5, 7, 11])"]},"execution_count":11,"metadata":{},"output_type":"execute_result"}],"source":["# Final elements in the prime_numbers\n","prime_numbers"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.4"},"orig_nbformat":4,"vscode":{"interpreter":{"hash":"3ad933181bd8a04b432d3370b9dc3b0662ad032c4dfaa4e4f1596c548f763858"}}},"nbformat":4,"nbformat_minor":2} 2 | -------------------------------------------------------------------------------- /advanced/03_ordered_dictionary.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "attachments": {}, 5 | "cell_type": "markdown", 6 | "metadata": {}, 7 | "source": [ 8 | "### Ordered Dictionary in Python \n", 9 | "\n", 10 | "Ordered Dictionary preserves the order of the keys that are inserted. Regular dictionary doesn't hold the order of the keys." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "OrderedDict([('001', 'Afiz'), ('002', 'Bob')])\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "from collections import OrderedDict\n", 28 | "\n", 29 | "or_dict = OrderedDict({'001': 'Afiz', '002': 'Bob'})\n", 30 | "print(or_dict)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "OrderedDict([('001', 'Afiz'), ('002', 'Bob'), ('003', 'Catherine')])\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "or_dict['003'] = 'Catherine'\n", 48 | "print(or_dict)" 49 | ] 50 | }, 51 | { 52 | "attachments": {}, 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "As you can see above order of the keys are preserved in the `ordered dictionary` " 57 | ] 58 | } 59 | ], 60 | "metadata": { 61 | "kernelspec": { 62 | "display_name": "Python 3", 63 | "language": "python", 64 | "name": "python3" 65 | }, 66 | "language_info": { 67 | "codemirror_mode": { 68 | "name": "ipython", 69 | "version": 3 70 | }, 71 | "file_extension": ".py", 72 | "mimetype": "text/x-python", 73 | "name": "python", 74 | "nbconvert_exporter": "python", 75 | "pygments_lexer": "ipython3", 76 | "version": "3.10.4" 77 | }, 78 | "orig_nbformat": 4, 79 | "vscode": { 80 | "interpreter": { 81 | "hash": "3ad933181bd8a04b432d3370b9dc3b0662ad032c4dfaa4e4f1596c548f763858" 82 | } 83 | } 84 | }, 85 | "nbformat": 4, 86 | "nbformat_minor": 2 87 | } 88 | -------------------------------------------------------------------------------- /advanced/04_default_dict.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "attachments": {}, 5 | "cell_type": "markdown", 6 | "metadata": {}, 7 | "source": [ 8 | "### Default Dictionary\n", 9 | "\n", 10 | "default dictionary never raises `key error`. This is a convient way to initialize dictionaries" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 6, 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "defaultdict(, {})\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "from collections import defaultdict\n", 28 | "\n", 29 | "words = defaultdict(int)\n", 30 | "print(words)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 7, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "data": { 40 | "text/plain": [ 41 | "defaultdict(int, {'This': 1, 'is': 1, 'python': 1, 'tutorial': 1})" 42 | ] 43 | }, 44 | "execution_count": 7, 45 | "metadata": {}, 46 | "output_type": "execute_result" 47 | } 48 | ], 49 | "source": [ 50 | "sentence = 'This is python tutorial'\n", 51 | "for word in sentence.split():\n", 52 | " words[word] += 1\n", 53 | "\n", 54 | "words" 55 | ] 56 | }, 57 | { 58 | "attachments": {}, 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "In the above example, if the normal `dictionary` is used, you should have seen `KeyError` as none of the words present in the dict." 63 | ] 64 | } 65 | ], 66 | "metadata": { 67 | "kernelspec": { 68 | "display_name": "Python 3", 69 | "language": "python", 70 | "name": "python3" 71 | }, 72 | "language_info": { 73 | "codemirror_mode": { 74 | "name": "ipython", 75 | "version": 3 76 | }, 77 | "file_extension": ".py", 78 | "mimetype": "text/x-python", 79 | "name": "python", 80 | "nbconvert_exporter": "python", 81 | "pygments_lexer": "ipython3", 82 | "version": "3.10.4" 83 | }, 84 | "orig_nbformat": 4, 85 | "vscode": { 86 | "interpreter": { 87 | "hash": "3ad933181bd8a04b432d3370b9dc3b0662ad032c4dfaa4e4f1596c548f763858" 88 | } 89 | } 90 | }, 91 | "nbformat": 4, 92 | "nbformat_minor": 2 93 | } 94 | -------------------------------------------------------------------------------- /advanced/05_chained_map.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "attachments": {}, 5 | "cell_type": "markdown", 6 | "metadata": {}, 7 | "source": [ 8 | "### ChainMap in Python\n", 9 | "\n", 10 | "`ChainMap` from `collections` helps you to combine list of dictionaries into single mapping object. " 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 2, 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "ChainMap({'first_name': 'John', 'last_name': 'Anderson'}, {'country': 'England', 'profession': 'Cricketer'})\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "from collections import ChainMap\n", 28 | "\n", 29 | "details = {'first_name': 'John', 'last_name': 'Anderson'}\n", 30 | "more_details = {'country': 'England', 'profession': 'Cricketer'}\n", 31 | "\n", 32 | "chain = ChainMap(details, more_details)\n", 33 | "print(chain)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 4, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "['country', 'profession', 'first_name', 'last_name']" 45 | ] 46 | }, 47 | "execution_count": 4, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "# list the keys\n", 54 | "list(chain.keys())" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 5, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "data": { 64 | "text/plain": [ 65 | "['England', 'Cricketer', 'John', 'Anderson']" 66 | ] 67 | }, 68 | "execution_count": 5, 69 | "metadata": {}, 70 | "output_type": "execute_result" 71 | } 72 | ], 73 | "source": [ 74 | "# list the values\n", 75 | "list(chain.values())" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 7, 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "data": { 85 | "text/plain": [ 86 | "'England'" 87 | ] 88 | }, 89 | "execution_count": 7, 90 | "metadata": {}, 91 | "output_type": "execute_result" 92 | } 93 | ], 94 | "source": [ 95 | "# Get the country value\n", 96 | "chain['country']" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 8, 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "data": { 106 | "text/plain": [ 107 | "'Anderson'" 108 | ] 109 | }, 110 | "execution_count": 8, 111 | "metadata": {}, 112 | "output_type": "execute_result" 113 | } 114 | ], 115 | "source": [ 116 | "# Try another example \n", 117 | "chain['last_name']" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [] 126 | } 127 | ], 128 | "metadata": { 129 | "kernelspec": { 130 | "display_name": "Python 3", 131 | "language": "python", 132 | "name": "python3" 133 | }, 134 | "language_info": { 135 | "codemirror_mode": { 136 | "name": "ipython", 137 | "version": 3 138 | }, 139 | "file_extension": ".py", 140 | "mimetype": "text/x-python", 141 | "name": "python", 142 | "nbconvert_exporter": "python", 143 | "pygments_lexer": "ipython3", 144 | "version": "3.10.4" 145 | }, 146 | "orig_nbformat": 4, 147 | "vscode": { 148 | "interpreter": { 149 | "hash": "3ad933181bd8a04b432d3370b9dc3b0662ad032c4dfaa4e4f1596c548f763858" 150 | } 151 | } 152 | }, 153 | "nbformat": 4, 154 | "nbformat_minor": 2 155 | } 156 | -------------------------------------------------------------------------------- /advanced/06_pydantic.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [] 9 | } 10 | ], 11 | "metadata": { 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "nbformat": 4, 17 | "nbformat_minor": 2 18 | } 19 | -------------------------------------------------------------------------------- /advanced/Screen Recording 2022-12-15 at 4.34.55 PM.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/advanced/Screen Recording 2022-12-15 at 4.34.55 PM.mov -------------------------------------------------------------------------------- /basics/OOP_In_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7834db75-f155-4ac7-bfaa-ba9158ae5586", 6 | "metadata": {}, 7 | "source": [ 8 | "## Class Methods and Static Methods " 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "34d94fcd-6474-40aa-b404-d72c3a349272", 14 | "metadata": {}, 15 | "source": [ 16 | "**Class Methods: Class methods work with class variables and are accessible using the name rather than its object.** \n", 17 | "\n", 18 | "**💡 Class methods are accessed using the class name and can be accessed without creating a class object** \n", 19 | "\n", 20 | "`@classmethod` decorator is used to create class methods. `cls` is used to refer to the class just like `self` is used to refer to the object of the class. " 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 2, 26 | "id": "0fc8d165-f7aa-4bf0-b903-cdadad5387f8", 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "name": "stdout", 31 | "output_type": "stream", 32 | "text": [ 33 | "Rajasthan Royals\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "class Player:\n", 39 | " teamName = 'Rajasthan Royals' # class variables\n", 40 | "\n", 41 | " def __init__(self, name):\n", 42 | " self.name = name # creating instance variables\n", 43 | "\n", 44 | " @classmethod\n", 45 | " def getTeamName(cls):\n", 46 | " return cls.teamName\n", 47 | "\n", 48 | "\n", 49 | "print(Player.getTeamName())" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "id": "bc4096ec-01c7-4f6d-a53f-e85b0a26a36d", 55 | "metadata": {}, 56 | "source": [ 57 | "### Instance Method" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 5, 63 | "id": "f5623b44-cd14-4312-a35b-b5c280f4c304", 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "DD\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "class Player:\n", 76 | " teamName = 'Rajasthan Royals' # class variables\n", 77 | "\n", 78 | " def __init__(self, name, pre_teams=[]):\n", 79 | " self.name = name # creating instance variables\n", 80 | " self.previous_teams = pre_teams\n", 81 | " \n", 82 | " def list_previous_teams(self): # instance method\n", 83 | " for team in self.previous_teams:\n", 84 | " print(team)\n", 85 | "\n", 86 | "sanju = Player('Sanju Samson', ['DD'])\n", 87 | "sanju.list_previous_teams()" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "id": "e9b3795e-f436-4a8d-839c-54529b838b2c", 93 | "metadata": {}, 94 | "source": [ 95 | "### Static Method:\n", 96 | "\n", 97 | "are methods that are usually limited to class only and not their objects. They have no direct relation to class or instance variables. They are used as utility functions inside the class or when we don't want the inherited classes. \n", 98 | "\n", 99 | "`@staticmethod` decorator is used to define static methods." 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 6, 105 | "id": "48aab602-2f5e-4b0e-968e-e13dbffe6014", 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "I am a static method.\n", 113 | "I am a static method.\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "class Player:\n", 119 | " teamName = 'Liverpool' # class variables\n", 120 | "\n", 121 | " def __init__(self, name):\n", 122 | " self.name = name # creating instance variables\n", 123 | "\n", 124 | " @staticmethod\n", 125 | " def demo():\n", 126 | " print(\"I am a static method.\")\n", 127 | "\n", 128 | "\n", 129 | "p1 = Player('lol')\n", 130 | "p1.demo()\n", 131 | "Player.demo()" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "id": "ed6fb460-b836-41bb-abdc-437a55c3ee9b", 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [] 141 | } 142 | ], 143 | "metadata": { 144 | "kernelspec": { 145 | "display_name": "default:Python", 146 | "language": "python", 147 | "name": "conda-env-default-py" 148 | }, 149 | "language_info": { 150 | "codemirror_mode": { 151 | "name": "ipython", 152 | "version": 3 153 | }, 154 | "file_extension": ".py", 155 | "mimetype": "text/x-python", 156 | "name": "python", 157 | "nbconvert_exporter": "python", 158 | "pygments_lexer": "ipython3", 159 | "version": "3.9.12" 160 | } 161 | }, 162 | "nbformat": 4, 163 | "nbformat_minor": 5 164 | } 165 | -------------------------------------------------------------------------------- /basics/async_example.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | async def function_1(): 4 | for i in range(100000): 5 | if i % 50000 == 0: 6 | print('Hello from function_1\n') 7 | 8 | # Pause the execution 9 | await asyncio.sleep(0.02) 10 | return 0 11 | 12 | async def function_2(): 13 | print(">>> I am from function_2 \n") 14 | return 0 15 | 16 | async def main(): 17 | f1 = loop.create_task(function_1()) 18 | f2 = loop.create_task(function_2()) 19 | await asyncio.wait([f1, f2]) 20 | 21 | 22 | 23 | loop = asyncio.get_event_loop() 24 | loop.run_until_complete(main()) 25 | loop.close() 26 | -------------------------------------------------------------------------------- /basics/list.md: -------------------------------------------------------------------------------- 1 | ## Python List functions with examples: 2 | 3 | Function Name | Function Description | Function Example (Input) | Function Example (Output) 4 | --- | --- | --- | --- 5 | `append()` | Adds an element to the end of the list. | `my_list = [1, 2, 3]`
`my_list.append(4)` | `[1, 2, 3, 4]` 6 | `extend()` | Adds elements from another iterable to the end of the list. | `my_list = [1, 2, 3]`
`my_list.extend([4, 5, 6])` | `[1, 2, 3, 4, 5, 6]` 7 | `insert()` | Inserts an element at a specific index. | `my_list = [1, 2, 4, 5]`
`my_list.insert(2, 3)` | `[1, 2, 3, 4, 5]` 8 | `remove()` | Removes the first occurrence of an element from the list. | `my_list = [1, 2, 3, 2]`
`my_list.remove(2)` | `[1, 3, 2]` 9 | `pop()` | Removes and returns an element at a specific index (default is the last element). | `my_list = [1, 2, 3]`
`my_list.pop(1)` | `[1, 3]` 10 | `index()` | Returns the index of the first occurrence of an element in the list. | `my_list = [1, 2, 3]`
`my_list.index(2)` | `1` 11 | `count()` | Returns the number of times an element appears in the list. | `my_list = [1, 2, 2, 3]`
`my_list.count(2)` | `2` 12 | `sort()` | Sorts the elements in the list. | `my_list = [3, 1, 2]`
`my_list.sort()` | `[1, 2, 3]` 13 | `reverse()` | Reverses the order of the elements in the list. | `my_list = [1, 2, 3]`
`my_list.reverse()` | `[3, 2, 1]` 14 | `copy()` | Returns a copy of the list. | `my_list = [1, 2, 3]`
`new_list = my_list.copy()` | `[1, 2, 3]` (in `new_list`) 15 | -------------------------------------------------------------------------------- /basics/merge_lists.py: -------------------------------------------------------------------------------- 1 | def merge_lists(a: list, b:list)-> list: 2 | return sorted(set(a + b)) 3 | 4 | 5 | a = [1,2,3,4,2,7,5] 6 | b = [4,1,9,8,7,6] 7 | c = merge_lists(a, b) 8 | print(c) -------------------------------------------------------------------------------- /basics/sets.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "64bae1c9-d598-4c68-b9c7-3b978ada8bbd", 6 | "metadata": {}, 7 | "source": [ 8 | "## Sets in Python\n", 9 | "\n", 10 | "What is set?\n", 11 | "Set is an unordered collection of unique items. Sets support mathematical operations like union, intersection and simmetric difference. \n", 12 | "\n", 13 | "1. Create empty set" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 1, 19 | "id": "7169c45e-de91-49f8-a97a-08105e8a4606", 20 | "metadata": { 21 | "tags": [] 22 | }, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "s = set()\n", 34 | "print(type(s))" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "id": "d7542cbc-52e8-47f8-b2f9-9e31345a4e4a", 40 | "metadata": {}, 41 | "source": [ 42 | "2. Create set with elements" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 2, 48 | "id": "7a049dcb-4984-409a-be38-157f7a516d00", 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "name": "stdout", 53 | "output_type": "stream", 54 | "text": [ 55 | "{1, 2, 3, 4, 5}\n" 56 | ] 57 | } 58 | ], 59 | "source": [ 60 | "s = set([1,2,3,4,5])\n", 61 | "print(s)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "id": "ef77cf32-39cf-45bd-a904-72d1cfca8b76", 67 | "metadata": {}, 68 | "source": [ 69 | "3. Add element to set" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 3, 75 | "id": "45588281-a0d7-4c6e-94bf-1f17fe44c688", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "{1, 2, 3, 4, 5, 6}\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "s.add(6)\n", 88 | "print(s)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "id": "843a1b24-bc39-4246-b325-4f6190796c6e", 94 | "metadata": {}, 95 | "source": [ 96 | "4. Remove element from set" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 4, 102 | "id": "a151da34-4c09-4394-b4bd-58f4aec64a61", 103 | "metadata": {}, 104 | "outputs": [ 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "{1, 2, 3, 4, 5}\n" 110 | ] 111 | } 112 | ], 113 | "source": [ 114 | "# Method 1\n", 115 | "s.remove(6)\n", 116 | "print(s)" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 5, 122 | "id": "12be6af6-2cd2-4958-80ce-08f32847a7fc", 123 | "metadata": {}, 124 | "outputs": [ 125 | { 126 | "name": "stdout", 127 | "output_type": "stream", 128 | "text": [ 129 | "{1, 2, 3, 4}\n" 130 | ] 131 | } 132 | ], 133 | "source": [ 134 | "# method 2\n", 135 | "s.discard(5)\n", 136 | "print(s)" 137 | ] 138 | }, 139 | { 140 | "cell_type": "markdown", 141 | "id": "3e1e1150-d0e9-4542-8602-6d9560293f4d", 142 | "metadata": {}, 143 | "source": [ 144 | "##### 5. Remove all the elements from list" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 6, 150 | "id": "581715d2-16bb-4c56-bf39-7a442fc8e466", 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "name": "stdout", 155 | "output_type": "stream", 156 | "text": [ 157 | "set()\n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "s.clear()\n", 163 | "print(s)" 164 | ] 165 | }, 166 | { 167 | "cell_type": "markdown", 168 | "id": "bcc9e96e-2936-46cd-8cdc-46e66fa955c0", 169 | "metadata": {}, 170 | "source": [ 171 | "##### 6. Check item exists in set" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 7, 177 | "id": "5b9a4210-04ff-4d9b-8372-40bc854f678b", 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "name": "stdout", 182 | "output_type": "stream", 183 | "text": [ 184 | "{'t', 'i', 'a', 'p', 'n', 'h', 'e', 'o', 'm', 'w', 's', ' ', 'y'}\n" 185 | ] 186 | } 187 | ], 188 | "source": [ 189 | "s = set('python is awesome')\n", 190 | "print(s)" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 8, 196 | "id": "813ae5af-94fa-47d8-befa-07858842344d", 197 | "metadata": {}, 198 | "outputs": [ 199 | { 200 | "data": { 201 | "text/plain": [ 202 | "False" 203 | ] 204 | }, 205 | "execution_count": 8, 206 | "metadata": {}, 207 | "output_type": "execute_result" 208 | } 209 | ], 210 | "source": [ 211 | "'x' in s" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "id": "d1cc9e7b-db01-4ee1-be73-1a4894189652", 217 | "metadata": {}, 218 | "source": [ 219 | "##### 7. Mathematical Operations\n", 220 | "7.1. Union" 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 9, 226 | "id": "7c2ba821-95c7-4482-9aba-a3ff3aafe0cc", 227 | "metadata": {}, 228 | "outputs": [ 229 | { 230 | "name": "stdout", 231 | "output_type": "stream", 232 | "text": [ 233 | "method - 1 ---> {1, 2, 3, 4, 5, 6, 7}\n", 234 | "method - 2 ---> {1, 2, 3, 4, 5, 6, 7}\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "a = {1,2,3,4,5}\n", 240 | "b = {2,6,7}\n", 241 | "print(f'method - 1 ---> {a.union(b)}')\n", 242 | "print(f'method - 2 ---> {a | b}')" 243 | ] 244 | }, 245 | { 246 | "cell_type": "markdown", 247 | "id": "1f1729aa-9599-4693-b968-cd76f1002cb4", 248 | "metadata": {}, 249 | "source": [ 250 | "7.2 Intersection" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 10, 256 | "id": "f90c7d87-b8f8-49cd-b6fb-d333ff28dc8f", 257 | "metadata": {}, 258 | "outputs": [ 259 | { 260 | "name": "stdout", 261 | "output_type": "stream", 262 | "text": [ 263 | "method - 1 ---> {2}\n", 264 | "method - 2 ---> {2}\n" 265 | ] 266 | } 267 | ], 268 | "source": [ 269 | "print(f'method - 1 ---> {a.intersection(b)}')\n", 270 | "print(f'method - 2 ---> {a & b}')" 271 | ] 272 | }, 273 | { 274 | "cell_type": "markdown", 275 | "id": "da0cc436-30a9-4381-9cbf-8e3a980f52a0", 276 | "metadata": {}, 277 | "source": [ 278 | "7.3 Difference" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 11, 284 | "id": "d6c8c84f-ddc5-4bd8-82c5-335a34cf2536", 285 | "metadata": {}, 286 | "outputs": [ 287 | { 288 | "name": "stdout", 289 | "output_type": "stream", 290 | "text": [ 291 | "method - 1 ---> {1, 3, 4, 5}\n", 292 | "method - 2 ---> {1, 3, 4, 5}\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "print(f'method - 1 ---> {a.difference(b)}')\n", 298 | "print(f'method - 2 ---> {a - b}')" 299 | ] 300 | }, 301 | { 302 | "cell_type": "markdown", 303 | "id": "66a51eda-9194-4050-90f9-144ed974c6c1", 304 | "metadata": {}, 305 | "source": [ 306 | "7.4 Simmetric Difference" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 12, 312 | "id": "d21a4868-719f-463b-831e-e2cfacde810b", 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "name": "stdout", 317 | "output_type": "stream", 318 | "text": [ 319 | "method - 1 ---> {1, 3, 4, 5, 6, 7}\n", 320 | "method - 2 ---> {1, 3, 4, 5, 6, 7}\n" 321 | ] 322 | } 323 | ], 324 | "source": [ 325 | "print(f'method - 1 ---> {a.symmetric_difference(b)}')\n", 326 | "print(f'method - 2 ---> {a ^ b}')" 327 | ] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "id": "1e3ef544-4199-4cfa-9203-f729924d164c", 332 | "metadata": {}, 333 | "source": [ 334 | "##### length of set" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 13, 340 | "id": "8393cdf9-4fc6-42a8-8d33-9cb0ad1ed66b", 341 | "metadata": {}, 342 | "outputs": [ 343 | { 344 | "data": { 345 | "text/plain": [ 346 | "5" 347 | ] 348 | }, 349 | "execution_count": 13, 350 | "metadata": {}, 351 | "output_type": "execute_result" 352 | } 353 | ], 354 | "source": [ 355 | "len(a)" 356 | ] 357 | }, 358 | { 359 | "cell_type": "markdown", 360 | "id": "35e574d9-e0b0-443f-b305-cd844465ab7a", 361 | "metadata": {}, 362 | "source": [ 363 | "##### Follow me -----> @itsafiz ⚡️" 364 | ] 365 | } 366 | ], 367 | "metadata": { 368 | "kernelspec": { 369 | "display_name": "default:Python", 370 | "language": "python", 371 | "name": "conda-env-default-py" 372 | }, 373 | "language_info": { 374 | "codemirror_mode": { 375 | "name": "ipython", 376 | "version": 3 377 | }, 378 | "file_extension": ".py", 379 | "mimetype": "text/x-python", 380 | "name": "python", 381 | "nbconvert_exporter": "python", 382 | "pygments_lexer": "ipython3", 383 | "version": "3.9.12" 384 | } 385 | }, 386 | "nbformat": 4, 387 | "nbformat_minor": 5 388 | } 389 | -------------------------------------------------------------------------------- /dsa/README.md: -------------------------------------------------------------------------------- 1 | ## Data Structures and Algorithms in Python -------------------------------------------------------------------------------- /dsa/binary_search.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "attachments": { 5 | "755b03ac-a95f-4da8-a1be-615ac545ad2e.png": { 6 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtcAAAB+CAIAAABgYKoFAAAMbGlDQ1BJQ0MgUHJvZmlsZQAASImVVwdYU8kWnluSkJDQAhGQEnoTRHqREkKLQUCqYCMkgYQSY0JQsaOLCq5dRLGiqyKKrq6ALCpiVxbB3hcLKsq6qIuiqLwJCei6r3zvfN/c+e+ZM/8pd+beOwBo9/Kk0hxUB4BcSZ4sLiKEOT4llUl6CohAB1CBCzDk8eVSVmxsFIAy2P9d3t0AiLK/6qzk+uf4fxU9gVDOBwCZCHG6QM7PhbgRAHwTXyrLA4Co1FtNz5Mq8XyI9WUwQIjXKnGmCu9R4nQVbhiwSYhjQ9wKgAaVx5NlAqB1D+qZ+fxMyKP1CWJXiUAsAUB7BMSBfBFPALEy9hG5uVOVuAxie2gvhRjGA3zSv+HM/Bt/+hA/j5c5hFV5DYhGqFguzeHN/D9L878lN0cx6MMWNqpIFhmnzB/W8Fb2VK4SUyHukqRHxyhrDXGvWKCqOwAoRaSITFTZoyZ8ORvWDzAgdhXwQrkQm0AcLsmJjlLr0zPE4RyI4WpBZ4jzOAkQG0K8RCgPi1fbbJNNjVP7QmsyZGyWWn+eJxvwq/T1QJGdyFLzvxEJOWp+TKtAlJAMMQVi63xxUjTEWhC7yLPjuWqb0QUidvSgjUwRp4zfGuI4oSQiRMWP5WfIwuPU9sW58sF8sW0iMSdajQ/liRIiVfXBTvN5A/HDXLBWoYSVOMgjlI+PGsxFIAwNU+WOPRdKEuPVPL3SvJA41VycIs2JVdvjlsKcCKXeEmIPeX68ei6elAcXp4ofz5DmxSao4sQ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zSHpFe4AF6qwG8+86frmJz2sf/6r0fu/G9AYTwe4V+AMkwMdenF3OEPiJAwAV5hvy22RzLMP2KkaE/oy2m1euuu27Tpk3H0Ys55PuGDRtCCwnVOAZM6OUarxhdwkd2wxPSexjc4YI7NHcEOOGEE7Zv337DDTcwnhIlipkwogPDgY0MIBG7C4fsiTGAMzzQHz3vOg7IYfIwkOLcc881QxDkggnmo9/eN+iuDNaW+138VqqjIQTIWLxBPyjdieya++Ot44aseXqqjZE23WlPTwHLE4qJK30tJqEkw5Toimw+EJ0WDuCq9DmqTYGpMETHU5U4jlQnKHt1dWV1dXl59SiosbKK3wruqwSCr5B7F28ByclttdsnH3YCDydG4+w+pI/w5T5V4oYKG4ot4qg850Si7LjjjjvOP//8K6+8UlXhbUoHtGXckvVG+S66KDy19syLPrmvUavAIBrWSJiF4W7WyR1u4kPdTfjXuQ91Ex8Wpo5+MOitLJHf6tLa8hKYABn7YAIIQ/gA+TXYkKexMPybjdpUu9lpt4DSMLf6XZ580hNeROwVQSiEJZF4sKUpVsTSl8HSUwDDCViEgRLMXvKF0SjSB/jIG/4QZSsdJQVKCpQUKClQUAqEoxCFFWNrCIUJlkmVFCgpUFKgpEBJASspcIzMmB6mIvqa00MjpC+zMuWSAiUFSgqUFCgpUFgKHCMzplEUUtjOoKzgwLblVVIgbxQou2XeWqQsT0mBY4cCxUYhheOexwi2PXbGjx01LbulHe1Y1qKkQBEpUGwUUnLPIva5sswlBUoK2EqBwq0MbW2IAtWr2CjERehyALgIUj6WFCgpUFLAJAXKlaEftcvpyY8yVqGQcgD4NXPpX1KgpEBJgZICGVKgnJ78iP//AdHIqnsKhsaAAAAAAElFTkSuQmCC" 7 | } 8 | }, 9 | "cell_type": "markdown", 10 | "id": "d2fb61ad-e052-479e-a521-491e4a3f131d", 11 | "metadata": {}, 12 | "source": [ 13 | "> **QUESTION 1:** Alice has some cards with numbers written on them. She arranges the cards in decreasing order, and lays them out face down in a sequence on a table. She challenges Bob to pick out the card containing a given number by turning over as few cards as possible. Write a function to help Bob locate the card.\n", 14 | "\n", 15 | "![image.png](attachment:755b03ac-a95f-4da8-a1be-615ac545ad2e.png)" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 4, 21 | "id": "54ab40b1-b9ce-4e6a-bdd9-6426efb814a3", 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "cards = [13,10, 11,10, 10, 7, 4, 3, 1, 0]\n", 26 | "query = 11\n", 27 | "output = 1" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "id": "0f95a690-2834-4f00-aedc-69a7cd925966", 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "def locate_card(cards: list, query: int) -> int:\n", 38 | " low, high = 0, len(cards)-1\n", 39 | " \n", 40 | " while True:\n", 41 | " mid = (low + high) // 2\n", 42 | " print(f'{low=} {high=}')\n", 43 | " \n", 44 | " if cards[mid] == query:\n", 45 | " return mid\n", 46 | " elif cards[mid] > query:\n", 47 | " low = mid + 1\n", 48 | " elif cards[mid] < query:\n", 49 | " high = mid - 1\n", 50 | " \n", 51 | " if low > high:\n", 52 | " return -1 " 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 21, 58 | "id": "c0fc4d59-ac9b-4163-a3cf-366bbb6014ae", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "cards = [13,11,10,10,10,7, 4, 3,2,1,0]\n", 63 | "query = 11\n", 64 | "output = 1" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 7, 70 | "id": "1fe8e3fd-98fd-4676-9f8c-6d0a57691ddc", 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "low=0 high=9\n" 78 | ] 79 | }, 80 | { 81 | "data": { 82 | "text/plain": [ 83 | "4" 84 | ] 85 | }, 86 | "execution_count": 7, 87 | "metadata": {}, 88 | "output_type": "execute_result" 89 | } 90 | ], 91 | "source": [ 92 | "locate_card(cards, 10)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 14, 98 | "id": "9cddb075-aec4-480d-b9f5-98e0f6495e6a", 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [ 102 | "def locate_card_1(cards: list, query: int) -> int:\n", 103 | " low, high = 0, len(cards)-1\n", 104 | " \n", 105 | " while True:\n", 106 | " mid = (low + high) // 2\n", 107 | " print(f'{low=} {high=} {mid=}')\n", 108 | " \n", 109 | " if cards[mid] == query:\n", 110 | " if cards[mid-1] != query:\n", 111 | " return mid\n", 112 | " high = mid -1 \n", 113 | " elif cards[mid] > query:\n", 114 | " low = mid + 1\n", 115 | " elif cards[mid] < query:\n", 116 | " high = mid - 1\n", 117 | " \n", 118 | " if low > high:\n", 119 | " return -1 " 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 24, 125 | "id": "19e1ac70-a146-4470-a0db-aab7412cd40f", 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "low=0 high=10 mid=5\n", 133 | "low=6 high=10 mid=8\n" 134 | ] 135 | }, 136 | { 137 | "data": { 138 | "text/plain": [ 139 | "8" 140 | ] 141 | }, 142 | "execution_count": 24, 143 | "metadata": {}, 144 | "output_type": "execute_result" 145 | } 146 | ], 147 | "source": [ 148 | "locate_card_1(cards, 2)" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 1, 154 | "id": "6fd9430f-6f18-4ac4-93a3-f893d898a431", 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "def binary_search(low, high, check_condition):\n", 159 | " \n", 160 | " while low <= high:\n", 161 | " \n", 162 | " mid = (low + high) // 2\n", 163 | " \n", 164 | " if check_condition(mid) == 'found':\n", 165 | " return mid\n", 166 | " elif check_condition(mid) == 'left':\n", 167 | " high = mid -1\n", 168 | " else:\n", 169 | " low = mid + 1\n", 170 | " \n", 171 | " return -1" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 4, 177 | "id": "d7cdef70-c0d5-46f8-895b-3926ff35570f", 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "def locate_card(cards, query):\n", 182 | " \n", 183 | " def check_condition(mid):\n", 184 | " if cards[mid] == query:\n", 185 | " if mid > 0 and cards[mid -1] == query:\n", 186 | " return 'left'\n", 187 | " else:\n", 188 | " return 'found'\n", 189 | " elif cards[mid] > query:\n", 190 | " return 'right'\n", 191 | " else:\n", 192 | " return 'left'\n", 193 | " \n", 194 | " return binary_search(0, len(cards), check_condition)" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 6, 200 | "id": "599e91ff-cd7a-4f10-8b0f-dcf575fe5ef0", 201 | "metadata": {}, 202 | "outputs": [ 203 | { 204 | "data": { 205 | "text/plain": [ 206 | "2" 207 | ] 208 | }, 209 | "execution_count": 6, 210 | "metadata": {}, 211 | "output_type": "execute_result" 212 | } 213 | ], 214 | "source": [ 215 | "cards = [13,11,10,10,10,7, 4, 3,2,1,0]\n", 216 | "\n", 217 | "locate_card(cards, 10)" 218 | ] 219 | }, 220 | { 221 | "cell_type": "markdown", 222 | "id": "879049c1-5873-4a38-8447-3e0d93ea24a1", 223 | "metadata": {}, 224 | "source": [ 225 | "### ✨ Binary Search\n", 226 | "\n", 227 | "Question: Given an array of integers nums sorted in ascending order, find the starting and ending position of a given number." 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 2, 233 | "id": "fd815cd9-c77b-4c7f-b7fa-ad9d6ba074ae", 234 | "metadata": {}, 235 | "outputs": [], 236 | "source": [ 237 | "def binary_search(low, high, check_condition):\n", 238 | " \n", 239 | " while low <= high:\n", 240 | " \n", 241 | " mid = (low + high) // 2\n", 242 | " \n", 243 | " if check_condition(mid) == 'found':\n", 244 | " return mid\n", 245 | " elif check_condition(mid) == 'left':\n", 246 | " high = mid -1\n", 247 | " else:\n", 248 | " low = mid + 1\n", 249 | " \n", 250 | " return -1" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 2, 256 | "id": "288941e9-fa2d-44ed-8f63-263deea130a0", 257 | "metadata": {}, 258 | "outputs": [], 259 | "source": [ 260 | "def first_position(cards, query):\n", 261 | " def check_condition(mid):\n", 262 | " if cards[mid] == query:\n", 263 | " if mid > 0 and cards[mid -1] == query:\n", 264 | " return 'left'\n", 265 | " else:\n", 266 | " return 'found'\n", 267 | " elif cards[mid] > query:\n", 268 | " return 'right'\n", 269 | " else:\n", 270 | " return 'left'\n", 271 | " return binary_search(0, len(cards), check_condition)\n", 272 | "\n", 273 | "def last_position(cards, query):\n", 274 | " def check_condition(mid):\n", 275 | " if cards[mid] == query:\n", 276 | " if mid < len(cards) - 1 and cards[mid + 1] == query:\n", 277 | " return 'right'\n", 278 | " else:\n", 279 | " return 'found'\n", 280 | " elif cards[mid] > query:\n", 281 | " return 'right'\n", 282 | " else:\n", 283 | " return 'left'\n", 284 | " return binary_search(0, len(cards), check_condition)\n", 285 | "\n", 286 | "def first_last_position(cards, query):\n", 287 | " return first_position(cards, query), last_position(cards, query)" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": 4, 293 | "id": "03afe84d-2090-43c9-a2f1-3a5cc296cca2", 294 | "metadata": {}, 295 | "outputs": [ 296 | { 297 | "data": { 298 | "text/plain": [ 299 | "(2, 4)" 300 | ] 301 | }, 302 | "execution_count": 4, 303 | "metadata": {}, 304 | "output_type": "execute_result" 305 | } 306 | ], 307 | "source": [ 308 | "cards = [13,11,10,10,10,7, 4, 3,2,1,0]\n", 309 | "first_last_position(cards, 10)" 310 | ] 311 | }, 312 | { 313 | "cell_type": "markdown", 314 | "id": "38421bfb-5858-4d36-90b2-8eaab448f0f9", 315 | "metadata": {}, 316 | "source": [ 317 | "### Implement the **count_rotations** function using the generic binary_search function\n", 318 | "\n", 319 | "[7, 8, 1, 3, 4, 5, 6] --> middle 3 and answer lies in the left as 3 is less than last element" 320 | ] 321 | }, 322 | { 323 | "cell_type": "code", 324 | "execution_count": 5, 325 | "id": "d64ef365-5561-45c1-a0a8-427fef1f4692", 326 | "metadata": {}, 327 | "outputs": [], 328 | "source": [ 329 | "def count_rotations(nums):\n", 330 | " \n", 331 | " def condition(mid):\n", 332 | " if mid > 0 and nums[mid -1] > nums[mid]:\n", 333 | " return 'found'\n", 334 | " elif nums[mid] > nums[-1]:\n", 335 | " return 'right'\n", 336 | " else:\n", 337 | " return 'left'\n", 338 | " return binary_search(0, len(nums)-1, condition)" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 6, 344 | "id": "a2b5ba90-b0b2-45d1-a925-091dadf1475a", 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "2" 351 | ] 352 | }, 353 | "execution_count": 6, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "count_rotations([7, 8, 1, 3, 4, 5, 6])" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 7, 365 | "id": "706747df-6e83-4744-a69d-3a241005713e", 366 | "metadata": {}, 367 | "outputs": [ 368 | { 369 | "data": { 370 | "text/plain": [ 371 | "3" 372 | ] 373 | }, 374 | "execution_count": 7, 375 | "metadata": {}, 376 | "output_type": "execute_result" 377 | } 378 | ], 379 | "source": [ 380 | "count_rotations([9, 10, 11, 1, 2, 3, 4, 5, 6, 7, 8])" 381 | ] 382 | }, 383 | { 384 | "cell_type": "code", 385 | "execution_count": 9, 386 | "id": "fbb2e2ef-015a-431a-8f20-c767ebb74bc1", 387 | "metadata": {}, 388 | "outputs": [ 389 | { 390 | "data": { 391 | "text/plain": [ 392 | "2" 393 | ] 394 | }, 395 | "execution_count": 9, 396 | "metadata": {}, 397 | "output_type": "execute_result" 398 | } 399 | ], 400 | "source": [ 401 | "count_rotations([7, 8, 1,1,1, 3,3,3, 4, 5, 6])" 402 | ] 403 | }, 404 | { 405 | "cell_type": "markdown", 406 | "id": "67006a68-ce5e-49e5-b71f-257433ddea2e", 407 | "metadata": {}, 408 | "source": [ 409 | "#### Searching in rotated list \n", 410 | "\n", 411 | "[5, 6, 9, 0, 2, 3, 4] -- target 2 , output --> 5" 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": 15, 417 | "id": "6c78efa8-cb09-4cc2-a5a5-9b36eddb99ac", 418 | "metadata": {}, 419 | "outputs": [], 420 | "source": [ 421 | "def find_number(nums, target):\n", 422 | " \n", 423 | " def find_rotation(nums):\n", 424 | " \n", 425 | " def condition(mid):\n", 426 | " if mid > 0 and nums[mid] < nums[mid - 1]:\n", 427 | " return 'found'\n", 428 | " elif nums[mid] > nums[-1]:\n", 429 | " return 'right'\n", 430 | " else:\n", 431 | " return 'left'\n", 432 | " \n", 433 | " return binary_search(0, len(nums), condition)\n", 434 | " \n", 435 | " rotation_point = find_rotation(nums)\n", 436 | " \n", 437 | " print(f'{rotation_point = }') \n", 438 | " \n", 439 | " \n", 440 | " def condition(mid):\n", 441 | " \n", 442 | " if nums[mid] == target:\n", 443 | " return 'found'\n", 444 | " elif nums[mid] > target:\n", 445 | " return 'left'\n", 446 | " else:\n", 447 | " return 'right'\n", 448 | " \n", 449 | " low = 0\n", 450 | " high = len(nums)\n", 451 | " \n", 452 | " if nums[rotation_point] < target and nums[-1] > target:\n", 453 | " low = rotation_point + 1 \n", 454 | " else:\n", 455 | " high = rotation_point - 1 \n", 456 | " \n", 457 | " return binary_search(low, high, condition)\n", 458 | " " 459 | ] 460 | }, 461 | { 462 | "cell_type": "code", 463 | "execution_count": 16, 464 | "id": "a0ed3ff9-8d24-415d-bd90-4f3daa71a726", 465 | "metadata": {}, 466 | "outputs": [ 467 | { 468 | "name": "stdout", 469 | "output_type": "stream", 470 | "text": [ 471 | "rotation_point = 3\n" 472 | ] 473 | }, 474 | { 475 | "data": { 476 | "text/plain": [ 477 | "4" 478 | ] 479 | }, 480 | "execution_count": 16, 481 | "metadata": {}, 482 | "output_type": "execute_result" 483 | } 484 | ], 485 | "source": [ 486 | "find_number([5, 6, 9, 0, 2, 3, 4], 2)" 487 | ] 488 | }, 489 | { 490 | "cell_type": "code", 491 | "execution_count": 17, 492 | "id": "22f8c733-fc63-42e6-aa8c-d37a626ead25", 493 | "metadata": {}, 494 | "outputs": [ 495 | { 496 | "name": "stdout", 497 | "output_type": "stream", 498 | "text": [ 499 | "rotation_point = 3\n" 500 | ] 501 | }, 502 | { 503 | "data": { 504 | "text/plain": [ 505 | "2" 506 | ] 507 | }, 508 | "execution_count": 17, 509 | "metadata": {}, 510 | "output_type": "execute_result" 511 | } 512 | ], 513 | "source": [ 514 | "find_number([5, 6, 9, 0, 2, 3, 4], 9)" 515 | ] 516 | }, 517 | { 518 | "cell_type": "code", 519 | "execution_count": 18, 520 | "id": "b7991d60-68b4-494d-98e8-6e23e3fdfa8a", 521 | "metadata": {}, 522 | "outputs": [ 523 | { 524 | "name": "stdout", 525 | "output_type": "stream", 526 | "text": [ 527 | "rotation_point = 3\n" 528 | ] 529 | }, 530 | { 531 | "data": { 532 | "text/plain": [ 533 | "-1" 534 | ] 535 | }, 536 | "execution_count": 18, 537 | "metadata": {}, 538 | "output_type": "execute_result" 539 | } 540 | ], 541 | "source": [ 542 | "find_number([5, 6, 9, 0, 2, 3, 4], 88)" 543 | ] 544 | }, 545 | { 546 | "cell_type": "code", 547 | "execution_count": null, 548 | "id": "f2bfe6b9-51ae-41aa-a034-928ff1a80feb", 549 | "metadata": {}, 550 | "outputs": [], 551 | "source": [] 552 | } 553 | ], 554 | "metadata": { 555 | "kernelspec": { 556 | "display_name": "default:Python", 557 | "language": "python", 558 | "name": "conda-env-default-py" 559 | }, 560 | "language_info": { 561 | "codemirror_mode": { 562 | "name": "ipython", 563 | "version": 3 564 | }, 565 | "file_extension": ".py", 566 | "mimetype": "text/x-python", 567 | "name": "python", 568 | "nbconvert_exporter": "python", 569 | "pygments_lexer": "ipython3", 570 | "version": "3.9.12" 571 | } 572 | }, 573 | "nbformat": 4, 574 | "nbformat_minor": 5 575 | } 576 | -------------------------------------------------------------------------------- /dsa/binary_search_tree.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "fcf2ab9b-7b40-440e-9748-787445308e30", 6 | "metadata": {}, 7 | "source": [ 8 | "### ✅ Binary Search Tree implementation in Python : @itsafiz" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 16, 14 | "id": "066faec4-3dee-47ce-a0ec-adb36266e469", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "class Node:\n", 19 | " def __init__(self, key):\n", 20 | " self.key = key\n", 21 | " self.left, self.right = None, None\n", 22 | " \n", 23 | " def __repr__(self):\n", 24 | " return f'{self.key}'\n", 25 | " \n", 26 | " def __str__(self):\n", 27 | " return f'{self.key}'" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "id": "1b1e7c27-e0b0-4e63-8878-83cb2dfca40f", 33 | "metadata": {}, 34 | "source": [ 35 | "#### Insert " 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 10, 41 | "id": "d80ae3c8-3b16-4281-b99e-ccd9c4d50eff", 42 | "metadata": { 43 | "tags": [] 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "def insert(node, key):\n", 48 | " if node is None:\n", 49 | " node = Node(key)\n", 50 | " elif node.key > key:\n", 51 | " node.left = insert(node.left, key)\n", 52 | " elif node.key < key:\n", 53 | " node.right = insert(node.right, key)\n", 54 | " return node" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "id": "17cc344e-5135-421a-9916-1dca035c6869", 60 | "metadata": { 61 | "tags": [] 62 | }, 63 | "source": [ 64 | "#### Inorder Traversal" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 3, 70 | "id": "77da0f59-549d-4f2a-8621-41b480732f11", 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "def inorder(node):\n", 75 | " if node is None:\n", 76 | " return []\n", 77 | " return (inorder(node.left) + [node.key] + inorder(node.right))" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 11, 83 | "id": "113db9bb-49b4-45dd-be31-6948079db389", 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "r = Node(50)\n", 88 | "for i in [30, 70, 10, 60, 88, 35, 65, 5]:\n", 89 | " r = insert(r, i)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 5, 95 | "id": "6e9df193-b911-4202-ac31-58711f8a1644", 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "data": { 100 | "text/plain": [ 101 | "[5, 10, 20, 25, 50, 55, 60, 65, 70]" 102 | ] 103 | }, 104 | "execution_count": 5, 105 | "metadata": {}, 106 | "output_type": "execute_result" 107 | } 108 | ], 109 | "source": [ 110 | "inorder(r)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "id": "a83f6abf-060f-4731-b55b-0ac4106a4aa5", 116 | "metadata": {}, 117 | "source": [ 118 | "# ✅ Traversing a Binary Tree" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "id": "90fff442-dc8d-46ca-a340-d88014d9789a", 124 | "metadata": {}, 125 | "source": [ 126 | "### 1️⃣ Inorder Tree Traversal" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 5, 132 | "id": "ff5964ba-6cf2-4161-8de5-64066e20a041", 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "data": { 137 | "text/plain": [ 138 | "[5, 10, 30, 35, 50, 60, 65, 70, 88]" 139 | ] 140 | }, 141 | "execution_count": 5, 142 | "metadata": {}, 143 | "output_type": "execute_result" 144 | } 145 | ], 146 | "source": [ 147 | "def inorder(node):\n", 148 | " if node is None:\n", 149 | " return []\n", 150 | " return (inorder(node.left) + [node.key] + inorder(node.right))\n", 151 | "\n", 152 | "inorder(r)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "id": "276aa824-35e5-4330-a768-7f5642997b94", 158 | "metadata": {}, 159 | "source": [ 160 | "#### 2️⃣ Pre-Order Tree traversal" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 6, 166 | "id": "8a4ff187-29ba-474e-8f8f-de943fa48687", 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "data": { 171 | "text/plain": [ 172 | "[50, 30, 10, 5, 35, 70, 60, 65, 88]" 173 | ] 174 | }, 175 | "execution_count": 6, 176 | "metadata": {}, 177 | "output_type": "execute_result" 178 | } 179 | ], 180 | "source": [ 181 | "def preorder(node):\n", 182 | " if node is None:\n", 183 | " return []\n", 184 | " return ([node.key]+ preorder(node.left) + preorder(node.right))\n", 185 | "preorder(r)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "markdown", 190 | "id": "accad9de-56b6-4c65-b0cb-1bfe8f5766e4", 191 | "metadata": {}, 192 | "source": [ 193 | "#### 3️⃣ Post-Order Tree traversal" 194 | ] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": 7, 199 | "id": "57303be0-954d-457a-81b9-5a9e546ddbc8", 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "data": { 204 | "text/plain": [ 205 | "[5, 10, 35, 30, 65, 60, 88, 70, 50]" 206 | ] 207 | }, 208 | "execution_count": 7, 209 | "metadata": {}, 210 | "output_type": "execute_result" 211 | } 212 | ], 213 | "source": [ 214 | "def postorder(node):\n", 215 | " if node is None:\n", 216 | " return []\n", 217 | " return (postorder(node.left) + \n", 218 | " postorder(node.right) + \n", 219 | " [node.key])\n", 220 | "postorder(r)" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "id": "a9f61fce-fb34-44ed-a832-cf3bf3a57cc1", 226 | "metadata": {}, 227 | "source": [ 228 | "🟡 If you like this content, follow me **@itsafiz**. RT and Like ❤️ for better reach" 229 | ] 230 | }, 231 | { 232 | "cell_type": "markdown", 233 | "id": "3b3fa586-32b4-48ca-9fe3-7d642a75e30d", 234 | "metadata": {}, 235 | "source": [ 236 | "# 🚀 Height and Size of a Binary Search Tree" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 12, 242 | "id": "703a35ce-4118-4c49-86ed-029b13a1ba5a", 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "data": { 247 | "text/plain": [ 248 | "4" 249 | ] 250 | }, 251 | "execution_count": 12, 252 | "metadata": {}, 253 | "output_type": "execute_result" 254 | } 255 | ], 256 | "source": [ 257 | "def height_of_bst(node):\n", 258 | " if node is None:\n", 259 | " return 0\n", 260 | " return 1 + max(height_of_bst(node.left), height_of_bst(node.right))\n", 261 | "height_of_bst(r)" 262 | ] 263 | }, 264 | { 265 | "cell_type": "markdown", 266 | "id": "6a658cf2-18ec-4d4b-8bf4-174978d64edc", 267 | "metadata": {}, 268 | "source": [ 269 | "🟡 If you like this content, follow me **@itsafiz**. RT and Like ❤️ for better reach" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 13, 275 | "id": "3be74cb1-feea-4d91-8d9b-851a1e4a250b", 276 | "metadata": {}, 277 | "outputs": [ 278 | { 279 | "data": { 280 | "text/plain": [ 281 | "9" 282 | ] 283 | }, 284 | "execution_count": 13, 285 | "metadata": {}, 286 | "output_type": "execute_result" 287 | } 288 | ], 289 | "source": [ 290 | "def size_of_bst(node):\n", 291 | " if node is None:\n", 292 | " return 0\n", 293 | " return 1 + size_of_bst(node.left) + size_of_bst(node.right)\n", 294 | "size_of_bst(r)" 295 | ] 296 | }, 297 | { 298 | "cell_type": "markdown", 299 | "id": "fbcd5d30-633a-48bf-bf16-108b474db3f4", 300 | "metadata": {}, 301 | "source": [ 302 | "# ➡️ Finding a Node in BST" 303 | ] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": 25, 308 | "id": "d667d48d-237b-435a-b352-d983b2f39d77", 309 | "metadata": {}, 310 | "outputs": [ 311 | { 312 | "name": "stdout", 313 | "output_type": "stream", 314 | "text": [ 315 | "node: 30, left-> 10 right -> 35\n" 316 | ] 317 | } 318 | ], 319 | "source": [ 320 | "def find_node(node, key):\n", 321 | " # node is not found\n", 322 | " if node is None:\n", 323 | " return None \n", 324 | " \n", 325 | " if node.key == key:\n", 326 | " return node\n", 327 | " if node.key > key:\n", 328 | " return find_node(node.left, key)\n", 329 | " if node.key < key:\n", 330 | " return find_node(node.right, key)\n", 331 | "\n", 332 | "n = find_node(r, 30)\n", 333 | "print(f'node: {n}, left-> {n.left} right -> {n.right}')" 334 | ] 335 | }, 336 | { 337 | "cell_type": "markdown", 338 | "id": "7651bb27-1e04-4f32-974a-649dff46573e", 339 | "metadata": {}, 340 | "source": [] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": null, 345 | "id": "3d2c0333-6879-4323-9dd9-03e291156c70", 346 | "metadata": {}, 347 | "outputs": [], 348 | "source": [] 349 | } 350 | ], 351 | "metadata": { 352 | "kernelspec": { 353 | "display_name": "default:Python", 354 | "language": "python", 355 | "name": "conda-env-default-py" 356 | }, 357 | "language_info": { 358 | "codemirror_mode": { 359 | "name": "ipython", 360 | "version": 3 361 | }, 362 | "file_extension": ".py", 363 | "mimetype": "text/x-python", 364 | "name": "python", 365 | "nbconvert_exporter": "python", 366 | "pygments_lexer": "ipython3", 367 | "version": "3.9.12" 368 | } 369 | }, 370 | "nbformat": 4, 371 | "nbformat_minor": 5 372 | } 373 | -------------------------------------------------------------------------------- /image-processing/faces.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/faces.jpg -------------------------------------------------------------------------------- /image-processing/girls.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/girls.jpeg -------------------------------------------------------------------------------- /image-processing/girls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/girls.png -------------------------------------------------------------------------------- /image-processing/group_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/group_image.jpg -------------------------------------------------------------------------------- /image-processing/nn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/nn.png -------------------------------------------------------------------------------- /image-processing/noise_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/noise_image.png -------------------------------------------------------------------------------- /image-processing/people.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/people.jpeg -------------------------------------------------------------------------------- /image-processing/puppy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/puppy.png -------------------------------------------------------------------------------- /image-processing/rrr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/image-processing/rrr.png -------------------------------------------------------------------------------- /image-processing/utils.py: -------------------------------------------------------------------------------- 1 | import matplotlib.image as img 2 | import matplotlib.pyplot as plt 3 | 4 | # reading the image 5 | dog = img.imread('puppy.png') 6 | 7 | def show_images(image_1, image_2, image_3): 8 | fig, (ax0, ax1, ax2) = plt.subplots(ncols=3, figsize=(8, 2)) 9 | ax0.imshow(image_1) 10 | ax0.set_title("RGB image") 11 | # ax0.axis('off') 12 | ax1.imshow(image_2) 13 | ax1.set_title("Hue channel") 14 | # ax1.axis('off') 15 | ax2.imshow(image_3) 16 | ax2.set_title("Value channel") 17 | # ax2.axis('off') 18 | 19 | fig.tight_layout() 20 | 21 | -------------------------------------------------------------------------------- /interesting/maplibre.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github", 7 | "colab_type": "text" 8 | }, 9 | "source": [ 10 | "\"Open" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "id": "HcMg7Tl8QyBB" 17 | }, 18 | "source": [ 19 | "[![image](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/giswqs/mapwidget/blob/master/docs/examples/maplibre.ipynb)\n", 20 | "[![image](https://img.shields.io/badge/Open-Planetary%20Computer-black?style=flat&logo=microsoft)](https://pccompute.westeurope.cloudapp.azure.com/compute/hub/user-redirect/git-pull?repo=https://github.com/giswqs/mapwidget&urlpath=lab/tree/mapwidget/docs/examples/maplibre.ipynb&branch=master)\n", 21 | "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/giswqs/mapwidget/blob/master/docs/examples/maplibre.ipynb)" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 12, 27 | "metadata": { 28 | "id": "6tvvhBkwQyBW" 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "!pip install mapwidget -q" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 13, 38 | "metadata": { 39 | "id": "xL3SV5UKQyBf" 40 | }, 41 | "outputs": [], 42 | "source": [ 43 | "import mapwidget.maplibre as mapwidget" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 14, 49 | "metadata": { 50 | "id": "zdyzrLatQyBh", 51 | "outputId": "77d02836-2fe9-424b-c5f1-2d61fbc9baff", 52 | "colab": { 53 | "base_uri": "https://localhost:8080/", 54 | "height": 629, 55 | "referenced_widgets": [ 56 | "5ffeeceff2d445cab28bc7a604359146", 57 | "fb93a0af168840628667bb5d117fe52b" 58 | ] 59 | } 60 | }, 61 | "outputs": [ 62 | { 63 | "output_type": "display_data", 64 | "data": { 65 | "text/plain": [ 66 | "Map(bounds=[0, 0, 0, 0], center=[20, 0], clicked_latlng=[None, None])" 67 | ], 68 | "application/vnd.jupyter.widget-view+json": { 69 | "version_major": 2, 70 | "version_minor": 0, 71 | "model_id": "5ffeeceff2d445cab28bc7a604359146" 72 | } 73 | }, 74 | "metadata": { 75 | "application/vnd.jupyter.widget-view+json": { 76 | "colab": { 77 | "custom_widget_manager": { 78 | "url": "https://ssl.gstatic.com/colaboratory-static/widgets/colab-cdn-widget-manager/b3e629b1971e1542/manager.min.js" 79 | } 80 | } 81 | } 82 | } 83 | } 84 | ], 85 | "source": [ 86 | "m = mapwidget.Map(center=[20, 0], zoom=2, height='600px')\n", 87 | "m" 88 | ] 89 | } 90 | ], 91 | "metadata": { 92 | "kernelspec": { 93 | "display_name": "Python 3 (ipykernel)", 94 | "language": "python", 95 | "name": "python3" 96 | }, 97 | "language_info": { 98 | "codemirror_mode": { 99 | "name": "ipython", 100 | "version": 3 101 | }, 102 | "file_extension": ".py", 103 | "mimetype": "text/x-python", 104 | "name": "python", 105 | "nbconvert_exporter": "python", 106 | "pygments_lexer": "ipython3", 107 | "version": "3.10.8" 108 | }, 109 | "colab": { 110 | "provenance": [], 111 | "include_colab_link": true 112 | }, 113 | "widgets": { 114 | "application/vnd.jupyter.widget-state+json": { 115 | "5ffeeceff2d445cab28bc7a604359146": { 116 | "model_module": "anywidget", 117 | "model_name": "AnyModel", 118 | "model_module_version": "0.2.0", 119 | "state": { 120 | "_dom_classes": [], 121 | "_model_module": "anywidget", 122 | "_model_module_version": "0.2.0", 123 | "_model_name": "AnyModel", 124 | "_view_count": null, 125 | "_view_module": "anywidget", 126 | "_view_module_version": "0.2.0", 127 | "_view_name": "AnyView", 128 | "bounds": [ 129 | -225.04721983033983, 130 | -83.7937344645258, 131 | 364.3268314215692, 132 | 75.2779787078189 133 | ], 134 | "center": [ 135 | -24.129228648052788, 136 | 69.63980579561598 137 | ], 138 | "clicked_latlng": [ 139 | null, 140 | null 141 | ], 142 | "height": "600px", 143 | "layout": "IPY_MODEL_fb93a0af168840628667bb5d117fe52b", 144 | "width": "100%", 145 | "zoom": 0.5695841332821526, 146 | "_esm": "import maplibregl from \"https://esm.sh/maplibre-gl@2.4.0\";\n\nexport function render(view) {\n // Header\n let center = view.model.get(\"center\");\n center.reverse();\n let zoom = view.model.get(\"zoom\");\n let width = view.model.get(\"width\");\n let height = view.model.get(\"height\");\n\n const div = document.createElement(\"div\");\n div.style.width = width;\n div.style.height = height;\n\n // Map content\n const map = new maplibregl.Map({\n container: div,\n style: \"https://demotiles.maplibre.org/style.json\", // stylesheet location\n center: center, // starting position [lng, lat]\n zoom: zoom, // starting zoom\n });\n\n map.on(\"click\", function (e) {\n view.model.set(\"clicked_latlng\", [e.lngLat.lat, e.lngLat.lng]);\n view.model.save_changes();\n });\n\n map.on(\"moveend\", function (e) {\n view.model.set(\"center\", [map.getCenter().lat, map.getCenter().lng]);\n let bbox = map.getBounds();\n let bounds = [bbox._sw.lng, bbox._sw.lat, bbox._ne.lng, bbox._ne.lat];\n view.model.set(\"bounds\", bounds);\n view.model.save_changes();\n });\n\n map.on(\"zoomend\", function (e) {\n view.model.set(\"center\", [map.getCenter().lat, map.getCenter().lng]);\n view.model.set(\"zoom\", map.getZoom());\n let bbox = map.getBounds();\n let bounds = [bbox._sw.lng, bbox._sw.lat, bbox._ne.lng, bbox._ne.lat];\n view.model.set(\"bounds\", bounds);\n view.model.save_changes();\n });\n\n // view.model.on(\"change:center\", function () {\n // let center = view.model.get(\"center\");\n // center.reverse();\n // map.setCenter(center);\n // });\n\n // view.model.on(\"change:zoom\", function () {\n // let zoom = view.model.get(\"zoom\");\n // map.setZoom(zoom);\n // });\n\n // Footer\n view.el.appendChild(div);\n}\n", 147 | "_css": "@import url(\"https://esm.sh/maplibre-gl@2.4.0?css\");\n", 148 | "_anywidget_id": "mapwidget.maplibre.Map" 149 | } 150 | }, 151 | "fb93a0af168840628667bb5d117fe52b": { 152 | "model_module": "@jupyter-widgets/base", 153 | "model_name": "LayoutModel", 154 | "model_module_version": "1.2.0", 155 | "state": { 156 | "_model_module": "@jupyter-widgets/base", 157 | "_model_module_version": "1.2.0", 158 | "_model_name": "LayoutModel", 159 | "_view_count": null, 160 | "_view_module": "@jupyter-widgets/base", 161 | "_view_module_version": "1.2.0", 162 | "_view_name": "LayoutView", 163 | "align_content": null, 164 | "align_items": null, 165 | "align_self": null, 166 | "border": null, 167 | "bottom": null, 168 | "display": null, 169 | "flex": null, 170 | "flex_flow": null, 171 | "grid_area": null, 172 | "grid_auto_columns": null, 173 | "grid_auto_flow": null, 174 | "grid_auto_rows": null, 175 | "grid_column": null, 176 | "grid_gap": null, 177 | "grid_row": null, 178 | "grid_template_areas": null, 179 | "grid_template_columns": null, 180 | "grid_template_rows": null, 181 | "height": null, 182 | "justify_content": null, 183 | "justify_items": null, 184 | "left": null, 185 | "margin": null, 186 | "max_height": null, 187 | "max_width": null, 188 | "min_height": null, 189 | "min_width": null, 190 | "object_fit": null, 191 | "object_position": null, 192 | "order": null, 193 | "overflow": null, 194 | "overflow_x": null, 195 | "overflow_y": null, 196 | "padding": null, 197 | "right": null, 198 | "top": null, 199 | "visibility": null, 200 | "width": null 201 | } 202 | } 203 | } 204 | } 205 | }, 206 | "nbformat": 4, 207 | "nbformat_minor": 0 208 | } -------------------------------------------------------------------------------- /interesting/pydata.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "490e86ca-1796-4c0e-87cc-5d58ef5ada33", 6 | "metadata": {}, 7 | "source": [ 8 | "### PyDataset - Access Datasets from Python\n", 9 | "\n", 10 | "`pip install pydataset`" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "c9fe00bf-bc66-4ac3-b4c5-6de5705618c2", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "!pip install pydataset -q" 21 | ] 22 | }, 23 | { 24 | "cell_type": "markdown", 25 | "id": "ba901b0a-260a-4322-a13b-0178dfdcf247", 26 | "metadata": {}, 27 | "source": [ 28 | "#### 1. Start with import `data`" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 1, 34 | "id": "b92efb5f-0681-4287-8ad2-f671553255ac", 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "from pydataset import data" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "id": "d3228f45-1a4d-4e71-ab4e-85513ccd1749", 44 | "metadata": {}, 45 | "source": [ 46 | "#### 2. Load Titanic Data" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 2, 52 | "id": "07c0f8a2-e9d4-4bb8-b0e2-6421e1a7b1b7", 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "titanic = data('titanic')" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "id": "8968ffec-c546-4769-9cd4-57ba5fc121ea", 62 | "metadata": {}, 63 | "source": [ 64 | "#### 3. Display data" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 3, 70 | "id": "0787ef2b-82d3-4c08-92cd-115d057638a9", 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "data": { 75 | "text/html": [ 76 | "
\n", 77 | "\n", 90 | "\n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | "
classagesexsurvived
11st classadultsmanyes
21st classadultsmanyes
31st classadultsmanyes
41st classadultsmanyes
51st classadultsmanyes
\n", 138 | "
" 139 | ], 140 | "text/plain": [ 141 | " class age sex survived\n", 142 | "1 1st class adults man yes\n", 143 | "2 1st class adults man yes\n", 144 | "3 1st class adults man yes\n", 145 | "4 1st class adults man yes\n", 146 | "5 1st class adults man yes" 147 | ] 148 | }, 149 | "execution_count": 3, 150 | "metadata": {}, 151 | "output_type": "execute_result" 152 | } 153 | ], 154 | "source": [ 155 | "titanic.head()" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "id": "88d0c936-71b8-4278-a8e5-13db0f6dbe95", 161 | "metadata": {}, 162 | "source": [ 163 | "Follow me @itsafiz for more content. " 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "id": "6a925153-8e3c-47da-8284-16a3829041c2", 170 | "metadata": {}, 171 | "outputs": [], 172 | "source": [] 173 | } 174 | ], 175 | "metadata": { 176 | "kernelspec": { 177 | "display_name": "default:Python", 178 | "language": "python", 179 | "name": "conda-env-default-py" 180 | }, 181 | "language_info": { 182 | "codemirror_mode": { 183 | "name": "ipython", 184 | "version": 3 185 | }, 186 | "file_extension": ".py", 187 | "mimetype": "text/x-python", 188 | "name": "python", 189 | "nbconvert_exporter": "python", 190 | "pygments_lexer": "ipython3", 191 | "version": "3.9.12" 192 | } 193 | }, 194 | "nbformat": 4, 195 | "nbformat_minor": 5 196 | } 197 | -------------------------------------------------------------------------------- /interesting/tryleap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github", 7 | "colab_type": "text" 8 | }, 9 | "source": [ 10 | "\"Open" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "edeb9027-1735-4700-81e7-45468b25bcd2", 17 | "metadata": { 18 | "id": "edeb9027-1735-4700-81e7-45468b25bcd2" 19 | }, 20 | "outputs": [], 21 | "source": [ 22 | "YOUR_API_KEY = 'Your Leap AI API Key'\n", 23 | "modelId = '8b1b897c-d66d-45a6-b8d7-8e32421d02cf' # You can use different model ID" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "id": "7b5bd28b-a513-49f2-b6f8-8c76c2e8a4f5", 30 | "metadata": { 31 | "id": "7b5bd28b-a513-49f2-b6f8-8c76c2e8a4f5", 32 | "outputId": "a2d286e2-abc9-430a-fda2-1c673e7a83b0" 33 | }, 34 | "outputs": [ 35 | { 36 | "name": "stderr", 37 | "output_type": "stream", 38 | "text": [ 39 | "/home/studio-lab-user/.conda/envs/default/lib/python3.9/site-packages/requests/__init__.py:102: RequestsDependencyWarning: urllib3 (1.26.13) or chardet (5.0.0)/charset_normalizer (2.0.12) doesn't match a supported version!\n", 40 | " warnings.warn(\"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported \"\n" 41 | ] 42 | }, 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "{\"status\":\"queued\",\"id\":\"f6445a7a-72d2-48a1-8f9c-bc6f7f7a3bdf\",\"prompt\":\"an astronaut riding a horse\",\"negativePrompt\":\"\",\"seed\":18218,\"width\":512,\"height\":512,\"numberOfImages\":1,\"steps\":25,\"createdAt\":\"2023-03-23T10:36:18.123Z\",\"promptStrength\":7,\"images\":[],\"modelId\":\"8b1b897c-d66d-45a6-b8d7-8e32421d02cf\"}\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "import requests\n", 53 | "\n", 54 | "url = f\"https://api.tryleap.ai/api/v1/images/models/{modelId}/inferences\"\n", 55 | "\n", 56 | "payload = {\n", 57 | " \"prompt\": \"an astronaut riding a horse\",\n", 58 | " \"steps\": 25,\n", 59 | " \"width\": 512,\n", 60 | " \"height\": 512,\n", 61 | " \"numberOfImages\": 1\n", 62 | "}\n", 63 | "headers = {\n", 64 | " \"accept\": \"application/json\",\n", 65 | " \"content-type\": \"application/json\",\n", 66 | " \"authorization\": f\"Bearer {YOUR_API_KEY}\"\n", 67 | "}\n", 68 | "\n", 69 | "response = requests.post(url, json=payload, headers=headers)\n", 70 | "\n", 71 | "print(response.text)\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "id": "da55ab50-dc94-4c8c-a859-f070c8543c7d", 78 | "metadata": { 79 | "id": "da55ab50-dc94-4c8c-a859-f070c8543c7d", 80 | "outputId": "56cdc83b-162c-45b9-fe7c-ac6552b05bce" 81 | }, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "https://dreamtrain.s3.us-west-2.amazonaws.com/image-gen-f6445a7a-72d2-48a1-8f9c-bc6f7f7a3bdf/generated_images/0.png\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "import requests\n", 93 | "\n", 94 | "url = f\"https://api.tryleap.ai/api/v1/images/models/{modelId}/inferences/f6445a7a-72d2-48a1-8f9c-bc6f7f7a3bdf\"\n", 95 | "\n", 96 | "headers = {\"authorization\": f\"Bearer {YOUR_API_KEY}\"}\n", 97 | "\n", 98 | "response = requests.get(url, headers=headers)\n", 99 | "\n", 100 | "print(response.json()['images'][0]['uri'])" 101 | ] 102 | } 103 | ], 104 | "metadata": { 105 | "kernelspec": { 106 | "display_name": "default:Python", 107 | "language": "python", 108 | "name": "conda-env-default-py" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": { 112 | "name": "ipython", 113 | "version": 3 114 | }, 115 | "file_extension": ".py", 116 | "mimetype": "text/x-python", 117 | "name": "python", 118 | "nbconvert_exporter": "python", 119 | "pygments_lexer": "ipython3", 120 | "version": "3.9.12" 121 | }, 122 | "colab": { 123 | "provenance": [], 124 | "include_colab_link": true 125 | } 126 | }, 127 | "nbformat": 4, 128 | "nbformat_minor": 5 129 | } -------------------------------------------------------------------------------- /ml-apps/AA_wordsearch.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "de41bbfc-6095-4ea2-a7dd-80a7b025eb97", 6 | "metadata": {}, 7 | "source": [ 8 | "# ⚡️ Search words in Audio file 🔊 using 🔸 AssemblyAI 🔸" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "2a8f3349-34a8-4993-a83a-8f614f51fce9", 14 | "metadata": {}, 15 | "source": [ 16 | "### ✅ Submit Audio file to get the transcription" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "id": "d38c513e-ed83-4b68-8cc8-756da668c1a9", 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "import requests\n", 27 | "from config import api_key\n", 28 | "headers = {\n", 29 | " \"authorization\": api_key,\n", 30 | " \"content-type\": \"application/json\"\n", 31 | "}\n", 32 | "\n", 33 | "endpoint = \"https://api.assemblyai.com/v2/transcript\"\n", 34 | "json = {\n", 35 | " \"audio_url\": \"https://bit.ly/3rBnQ8i\",\n", 36 | " \"sentiment_analysis\": True\n", 37 | "}\n", 38 | "response = requests.post(endpoint, json=json, headers=headers)\n", 39 | "transcription_id = response.json().get('id')" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 3, 45 | "id": "b6a9c5b2-9fd3-4427-a41c-56d62f0d1893", 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "(, 'ov01qv3oku-dea6-4f8c-a20c-ba6c638ae5ea')" 52 | ] 53 | }, 54 | "execution_count": 3, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "response, transcription_id" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "id": "41f37867-d872-4bc7-9cb3-464322068184", 66 | "metadata": {}, 67 | "source": [ 68 | "### ✅ Get the full transcription" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 12, 74 | "id": "1d6c0355-c588-4456-aedb-3392d4f53d3e", 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "data": { 79 | "text/plain": [ 80 | "'Ted talks are recorded live at the Ted conference. This episode features psychologist and happiness '" 81 | ] 82 | }, 83 | "execution_count": 12, 84 | "metadata": {}, 85 | "output_type": "execute_result" 86 | } 87 | ], 88 | "source": [ 89 | "endpoint = f\"https://api.assemblyai.com/v2/transcript/{transcription_id}\"\n", 90 | "res = requests.get(endpoint, headers=headers)\n", 91 | "res.json().get('text')[:100]" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "id": "522b6d7f-12ec-4fd7-ae63-13c3e446097b", 97 | "metadata": {}, 98 | "source": [ 99 | "### ✅ Search for words " 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 14, 105 | "id": "ec5352d3-266c-4f7a-8967-fda71c4d634a", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "endpoint = f\"https://api.assemblyai.com/v2/transcript/{transcription_id}/word-search?words=happiness\"\n", 110 | "res = requests.get(endpoint, headers=headers)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 15, 116 | "id": "b6f67e22-53b4-48c2-b9ac-509ca5b83351", 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "data": { 121 | "text/plain": [ 122 | "{'id': 'ov01qv3oku-dea6-4f8c-a20c-ba6c638ae5ea',\n", 123 | " 'total_count': 29,\n", 124 | " 'matches': [{'text': 'happiness',\n", 125 | " 'count': 29,\n", 126 | " 'timestamps': [[13004, 13366],\n", 127 | " [261444, 262150],\n", 128 | " [265956, 266650],\n", 129 | " [319070, 319694],\n", 130 | " [320676, 321086],\n", 131 | " [327482, 327926],\n", 132 | " [336794, 337130],\n", 133 | " [338774, 339290],\n", 134 | " [471744, 472358],\n", 135 | " [495446, 495866],\n", 136 | " [515762, 516182],\n", 137 | " [519542, 519986],\n", 138 | " [522002, 522446],\n", 139 | " [525734, 526166],\n", 140 | " [533822, 534302],\n", 141 | " [563762, 564146],\n", 142 | " [567684, 568046],\n", 143 | " [582444, 582914],\n", 144 | " [637992, 638330],\n", 145 | " [643188, 643550],\n", 146 | " [646950, 647870],\n", 147 | " [654444, 654914],\n", 148 | " [774098, 774542],\n", 149 | " [810614, 811106],\n", 150 | " [835922, 836474],\n", 151 | " [855602, 855986],\n", 152 | " [868118, 868550],\n", 153 | " [1082664, 1083310],\n", 154 | " [1127882, 1128610]],\n", 155 | " 'indexes': [14,\n", 156 | " 699,\n", 157 | " 702,\n", 158 | " 837,\n", 159 | " 841,\n", 160 | " 864,\n", 161 | " 903,\n", 162 | " 910,\n", 163 | " 1377,\n", 164 | " 1427,\n", 165 | " 1494,\n", 166 | " 1507,\n", 167 | " 1513,\n", 168 | " 1526,\n", 169 | " 1549,\n", 170 | " 1627,\n", 171 | " 1639,\n", 172 | " 1690,\n", 173 | " 1890,\n", 174 | " 1907,\n", 175 | " 1917,\n", 176 | " 1939,\n", 177 | " 2304,\n", 178 | " 2412,\n", 179 | " 2473,\n", 180 | " 2519,\n", 181 | " 2556,\n", 182 | " 3299,\n", 183 | " 3442]}]}" 184 | ] 185 | }, 186 | "execution_count": 15, 187 | "metadata": {}, 188 | "output_type": "execute_result" 189 | } 190 | ], 191 | "source": [ 192 | "res.json()" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 16, 198 | "id": "2a1c98b8-3112-484c-81e1-5e1d470f2b94", 199 | "metadata": {}, 200 | "outputs": [ 201 | { 202 | "data": { 203 | "text/plain": [ 204 | "{'id': 'ov01qv3oku-dea6-4f8c-a20c-ba6c638ae5ea',\n", 205 | " 'total_count': 2,\n", 206 | " 'matches': [{'text': 'talks',\n", 207 | " 'count': 1,\n", 208 | " 'timestamps': [[8806, 9142]],\n", 209 | " 'indexes': [1]},\n", 210 | " {'text': 'episode',\n", 211 | " 'count': 1,\n", 212 | " 'timestamps': [[11312, 11710]],\n", 213 | " 'indexes': [10]}]}" 214 | ] 215 | }, 216 | "execution_count": 16, 217 | "metadata": {}, 218 | "output_type": "execute_result" 219 | } 220 | ], 221 | "source": [ 222 | "endpoint = f\"https://api.assemblyai.com/v2/transcript/{transcription_id}/word-search?words=talks,episode\"\n", 223 | "res = requests.get(endpoint, headers=headers)\n", 224 | "res.json()" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": null, 230 | "id": "750093c5-fe4f-4f96-a6c6-4ecd50a2ab65", 231 | "metadata": {}, 232 | "outputs": [], 233 | "source": [] 234 | } 235 | ], 236 | "metadata": { 237 | "kernelspec": { 238 | "display_name": "default:Python", 239 | "language": "python", 240 | "name": "conda-env-default-py" 241 | }, 242 | "language_info": { 243 | "codemirror_mode": { 244 | "name": "ipython", 245 | "version": 3 246 | }, 247 | "file_extension": ".py", 248 | "mimetype": "text/x-python", 249 | "name": "python", 250 | "nbconvert_exporter": "python", 251 | "pygments_lexer": "ipython3", 252 | "version": "3.9.12" 253 | } 254 | }, 255 | "nbformat": 4, 256 | "nbformat_minor": 5 257 | } 258 | -------------------------------------------------------------------------------- /ml-apps/flip-image/README.md: -------------------------------------------------------------------------------- 1 | # Flip the image in less than 10 lines of code. 2 | 3 | Demo Link: https://huggingface.co/spaces/afiz/flip-image 4 | -------------------------------------------------------------------------------- /ml-apps/flip-image/app.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def flip_image(x): 4 | return np.fliplr(x) 5 | 6 | import gradio as gr 7 | 8 | gr.Interface(fn=flip_image, inputs="image", outputs="image").launch(); 9 | -------------------------------------------------------------------------------- /ml-apps/monster.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "39608202-38ab-42a0-aeb2-dd48eb6ff36a", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from config import monster_api, monster_bearer # get your keys from MonsterAPI for FREE\n", 11 | "from IPython.display import Image, display" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": null, 17 | "id": "5e6a34e8-09f2-488e-aa4f-808fae20f770", 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "import requests\n", 22 | "import json\n", 23 | "\n", 24 | "url = \"https://api.monsterapi.ai/apis/add-task\"\n", 25 | "\n", 26 | "payload = json.dumps({\n", 27 | " \"model\": \"txt2img\",\n", 28 | " \"data\": {\n", 29 | " \"prompt\": \"Elon Musk as the Joker taking an apple from Steve Jobs, intricate, elegant, highly detailed, digital painting, artstation, concept art, matte, sharp focus, illustration, art by greg rutkowski and alphonse mucha\",\n", 30 | " \"negprompt\": \"\",\n", 31 | " \"samples\": 1,\n", 32 | " \"steps\": 50,\n", 33 | " \"aspect_ratio\": \"square\",\n", 34 | " \"guidance_scale\": 7.5,\n", 35 | " \"seed\": 2414\n", 36 | " }\n", 37 | "})\n", 38 | "headers = {\n", 39 | " 'x-api-key': monster_api,\n", 40 | " 'Authorization': f'Bearer {monster_bearer}',\n", 41 | " 'Content-Type': 'application/json'\n", 42 | "}\n", 43 | "\n", 44 | "response = requests.request(\"POST\", url, headers=headers, data=payload)\n", 45 | "print(response.text)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "id": "ab8a6c40-0b65-4982-9614-a41c33b364e1", 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "url = \"https://api.monsterapi.ai/apis/task-status\"\n", 56 | "\n", 57 | "payload = json.dumps({\n", 58 | " \"process_id\": '1c3f8855-b25a-11ed-850e-075d1b526852'\n", 59 | "})\n", 60 | "response = requests.request(\"POST\", url, headers=headers, data=payload)\n", 61 | "res = json.loads(response.text)\n", 62 | "display(Image(res['response_data']['result']['output'][0]))" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "id": "245d3954-d3b8-4e82-9ff2-fc152b020fab", 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [] 72 | } 73 | ], 74 | "metadata": { 75 | "kernelspec": { 76 | "display_name": "default:Python", 77 | "language": "python", 78 | "name": "conda-env-default-py" 79 | }, 80 | "language_info": { 81 | "codemirror_mode": { 82 | "name": "ipython", 83 | "version": 3 84 | }, 85 | "file_extension": ".py", 86 | "mimetype": "text/x-python", 87 | "name": "python", 88 | "nbconvert_exporter": "python", 89 | "pygments_lexer": "ipython3", 90 | "version": "3.9.12" 91 | }, 92 | "widgets": { 93 | "application/vnd.jupyter.widget-state+json": { 94 | "state": {}, 95 | "version_major": 2, 96 | "version_minor": 0 97 | } 98 | } 99 | }, 100 | "nbformat": 4, 101 | "nbformat_minor": 5 102 | } 103 | -------------------------------------------------------------------------------- /ml-apps/oneai/htmltosummary.py: -------------------------------------------------------------------------------- 1 | 2 | # get the api_key from oneai.com 3 | from config import api_key 4 | 5 | # pip install oneai 6 | import oneai 7 | 8 | oneai.api_key = api_key 9 | 10 | pipeline = oneai.Pipeline( 11 | steps = [ 12 | oneai.skills.HtmlToArticle(), 13 | oneai.skills.Summarize(), 14 | ] 15 | ) 16 | 17 | output = pipeline.run('https://en.wikipedia.org/wiki/Natural_language_processing') 18 | 19 | print(output.html_article.summary.text) # prints the summary of the article 20 | -------------------------------------------------------------------------------- /ml-apps/oneai/htmltotext.py: -------------------------------------------------------------------------------- 1 | 2 | # get the api_key from oneai.com 3 | from config import api_key 4 | 5 | # pip install oneai 6 | import oneai 7 | 8 | oneai.api_key = api_key 9 | 10 | pipeline = oneai.Pipeline( 11 | steps = [ 12 | oneai.skills.HtmlToArticle(), 13 | ] 14 | ) 15 | 16 | output = pipeline.run('https://en.wikipedia.org/wiki/Natural_language_processing') 17 | 18 | print(output.html_article.text) 19 | -------------------------------------------------------------------------------- /ml-apps/tryleap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "edeb9027-1735-4700-81e7-45468b25bcd2", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "YOUR_API_KEY = 'GET Your API KEY from Leap AI'\n", 11 | "modelId = '8b1b897c-d66d-45a6-b8d7-8e32421d02cf'" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 2, 17 | "id": "7b5bd28b-a513-49f2-b6f8-8c76c2e8a4f5", 18 | "metadata": {}, 19 | "outputs": [ 20 | { 21 | "name": "stderr", 22 | "output_type": "stream", 23 | "text": [ 24 | "/home/studio-lab-user/.conda/envs/default/lib/python3.9/site-packages/requests/__init__.py:102: RequestsDependencyWarning: urllib3 (1.26.13) or chardet (5.0.0)/charset_normalizer (2.0.12) doesn't match a supported version!\n", 25 | " warnings.warn(\"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported \"\n" 26 | ] 27 | }, 28 | { 29 | "name": "stdout", 30 | "output_type": "stream", 31 | "text": [ 32 | "{\"status\":\"queued\",\"id\":\"f6445a7a-72d2-48a1-8f9c-bc6f7f7a3bdf\",\"prompt\":\"an astronaut riding a horse\",\"negativePrompt\":\"\",\"seed\":18218,\"width\":512,\"height\":512,\"numberOfImages\":1,\"steps\":25,\"createdAt\":\"2023-03-23T10:36:18.123Z\",\"promptStrength\":7,\"images\":[],\"modelId\":\"8b1b897c-d66d-45a6-b8d7-8e32421d02cf\"}\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "import requests\n", 38 | "\n", 39 | "url = f\"https://api.tryleap.ai/api/v1/images/models/{modelId}/inferences\"\n", 40 | "\n", 41 | "payload = {\n", 42 | " \"prompt\": \"an astronaut riding a horse\",\n", 43 | " \"steps\": 25,\n", 44 | " \"width\": 512,\n", 45 | " \"height\": 512,\n", 46 | " \"numberOfImages\": 1\n", 47 | "}\n", 48 | "headers = {\n", 49 | " \"accept\": \"application/json\",\n", 50 | " \"content-type\": \"application/json\",\n", 51 | " \"authorization\": f\"Bearer {YOUR_API_KEY}\"\n", 52 | "}\n", 53 | "\n", 54 | "response = requests.post(url, json=payload, headers=headers)\n", 55 | "\n", 56 | "print(response.text)\n" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 5, 62 | "id": "da55ab50-dc94-4c8c-a859-f070c8543c7d", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "https://dreamtrain.s3.us-west-2.amazonaws.com/image-gen-f6445a7a-72d2-48a1-8f9c-bc6f7f7a3bdf/generated_images/0.png\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "import requests\n", 75 | "\n", 76 | "url = f\"https://api.tryleap.ai/api/v1/images/models/{modelId}/inferences/f6445a7a-72d2-48a1-8f9c-bc6f7f7a3bdf\"\n", 77 | "\n", 78 | "headers = {\"authorization\": f\"Bearer {YOUR_API_KEY}\"}\n", 79 | "\n", 80 | "response = requests.get(url, headers=headers)\n", 81 | "\n", 82 | "print(response.json()['images'][0]['uri'])" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 3, 88 | "id": "c856af3f-f4a0-4b1d-be87-d7b098aa84f7", 89 | "metadata": {}, 90 | "outputs": [ 91 | { 92 | "name": "stdout", 93 | "output_type": "stream", 94 | "text": [ 95 | "[{\"id\":\"2b0add04-5069-43e7-9196-ddc7e2d7e486\",\"status\":\"finished\",\"prompt\":\"a picture of @me in new york\",\"negativePrompt\":\"\",\"seed\":53322,\"width\":512,\"height\":512,\"numberOfImages\":1,\"steps\":25,\"createdAt\":\"2023-03-21T11:45:11.437636+00:00\",\"promptStrength\":7,\"images\":[{\"id\":\"12f4bda1-29a5-4190-9a7a-ca4e19aa9cdd\",\"uri\":\"https://dreamtrain.s3.us-west-2.amazonaws.com/image-gen-2b0add04-5069-43e7-9196-ddc7e2d7e486/generated_images/0.png\",\"createdAt\":\"2023-03-21T11:45:26.206Z\"}],\"modelId\":\"8b1b897c-d66d-45a6-b8d7-8e32421d02cf\"},{\"id\":\"0b06aa73-d863-44d6-bfa4-52ca3421160e\",\"status\":\"finished\",\"prompt\":\"a picture of Ram Charan in new york\",\"negativePrompt\":\"\",\"seed\":2534,\"width\":512,\"height\":512,\"numberOfImages\":1,\"steps\":25,\"createdAt\":\"2023-03-21T11:48:58.667988+00:00\",\"promptStrength\":7,\"images\":[{\"id\":\"90aaae58-c5ff-400b-80b5-2de0332cc6d6\",\"uri\":\"https://dreamtrain.s3.us-west-2.amazonaws.com/image-gen-0b06aa73-d863-44d6-bfa4-52ca3421160e/generated_images/0.png\",\"createdAt\":\"2023-03-21T11:49:13.201Z\"}],\"modelId\":\"8b1b897c-d66d-45a6-b8d7-8e32421d02cf\"}]\n" 96 | ] 97 | } 98 | ], 99 | "source": [ 100 | "import requests\n", 101 | "\n", 102 | "url = f\"https://api.tryleap.ai/api/v1/images/models/{modelId}/inferences\"\n", 103 | "\n", 104 | "headers = {\"authorization\": f\"Bearer {YOUR_API_KEY}\"}\n", 105 | "\n", 106 | "response = requests.get(url, headers=headers)\n", 107 | "\n", 108 | "print(response.text)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 4, 114 | "id": "f566fc7c-0a80-4372-904d-c9720bb9e92e", 115 | "metadata": {}, 116 | "outputs": [ 117 | { 118 | "data": { 119 | "text/plain": [ 120 | "str" 121 | ] 122 | }, 123 | "execution_count": 4, 124 | "metadata": {}, 125 | "output_type": "execute_result" 126 | } 127 | ], 128 | "source": [ 129 | "data = response.text\n", 130 | "type(data)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 6, 136 | "id": "de28b50a-c5cb-4f27-b27c-20a46d78375a", 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "data": { 141 | "text/plain": [ 142 | "[{'id': '2b0add04-5069-43e7-9196-ddc7e2d7e486',\n", 143 | " 'status': 'finished',\n", 144 | " 'prompt': 'a picture of @me in new york',\n", 145 | " 'negativePrompt': '',\n", 146 | " 'seed': 53322,\n", 147 | " 'width': 512,\n", 148 | " 'height': 512,\n", 149 | " 'numberOfImages': 1,\n", 150 | " 'steps': 25,\n", 151 | " 'createdAt': '2023-03-21T11:45:11.437636+00:00',\n", 152 | " 'promptStrength': 7,\n", 153 | " 'images': [{'id': '12f4bda1-29a5-4190-9a7a-ca4e19aa9cdd',\n", 154 | " 'uri': 'https://dreamtrain.s3.us-west-2.amazonaws.com/image-gen-2b0add04-5069-43e7-9196-ddc7e2d7e486/generated_images/0.png',\n", 155 | " 'createdAt': '2023-03-21T11:45:26.206Z'}],\n", 156 | " 'modelId': '8b1b897c-d66d-45a6-b8d7-8e32421d02cf'},\n", 157 | " {'id': '0b06aa73-d863-44d6-bfa4-52ca3421160e',\n", 158 | " 'status': 'finished',\n", 159 | " 'prompt': 'a picture of Ram Charan in new york',\n", 160 | " 'negativePrompt': '',\n", 161 | " 'seed': 2534,\n", 162 | " 'width': 512,\n", 163 | " 'height': 512,\n", 164 | " 'numberOfImages': 1,\n", 165 | " 'steps': 25,\n", 166 | " 'createdAt': '2023-03-21T11:48:58.667988+00:00',\n", 167 | " 'promptStrength': 7,\n", 168 | " 'images': [{'id': '90aaae58-c5ff-400b-80b5-2de0332cc6d6',\n", 169 | " 'uri': 'https://dreamtrain.s3.us-west-2.amazonaws.com/image-gen-0b06aa73-d863-44d6-bfa4-52ca3421160e/generated_images/0.png',\n", 170 | " 'createdAt': '2023-03-21T11:49:13.201Z'}],\n", 171 | " 'modelId': '8b1b897c-d66d-45a6-b8d7-8e32421d02cf'}]" 172 | ] 173 | }, 174 | "execution_count": 6, 175 | "metadata": {}, 176 | "output_type": "execute_result" 177 | } 178 | ], 179 | "source": [ 180 | "len(response.json())" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "id": "22e2542a-2ebe-4d56-b5db-ba8933a76caa", 187 | "metadata": {}, 188 | "outputs": [], 189 | "source": [] 190 | } 191 | ], 192 | "metadata": { 193 | "kernelspec": { 194 | "display_name": "default:Python", 195 | "language": "python", 196 | "name": "conda-env-default-py" 197 | }, 198 | "language_info": { 199 | "codemirror_mode": { 200 | "name": "ipython", 201 | "version": 3 202 | }, 203 | "file_extension": ".py", 204 | "mimetype": "text/x-python", 205 | "name": "python", 206 | "nbconvert_exporter": "python", 207 | "pygments_lexer": "ipython3", 208 | "version": "3.9.12" 209 | } 210 | }, 211 | "nbformat": 4, 212 | "nbformat_minor": 5 213 | } 214 | -------------------------------------------------------------------------------- /oneAI/oneapi_config.py: -------------------------------------------------------------------------------- 1 | api_key = "5c5aa6c6-5a3f-411e-9590-e6fa42c2de4c" -------------------------------------------------------------------------------- /quizzes/1_magic_methods.MD: -------------------------------------------------------------------------------- 1 | Question: 1 2 | ![image](https://user-images.githubusercontent.com/5618143/210236267-f34e54f2-712b-4472-aae8-aacdacfc6e2e.png) 3 | 4 | Answer: Will be updated tomorrow :) 5 | -------------------------------------------------------------------------------- /quizzes/README.md: -------------------------------------------------------------------------------- 1 | # Python Quizzes 2 | 3 | | SN | Date | Question | Answer | Explanation | YouTube | 4 | | :---: | :---: | :---: |:---: | :---: | :---: | 5 | | 1 | 02/01/2023 | [Magic Methods](1_magic_methods.MD) | **TO BE UPDATED** | **TO BE UPDATED** | **TO BE UPDATED** | 6 | -------------------------------------------------------------------------------- /resources/cheat-sheets/python.md: -------------------------------------------------------------------------------- 1 | ![image](https://user-images.githubusercontent.com/5618143/204025469-cd5ab64a-876a-4e69-8e23-9c4c212776cc.png) 2 | 3 | 4 | ## Cheat Sheet - 1 5 | ![image](https://user-images.githubusercontent.com/5618143/204025602-30baccf2-037d-4e54-aa3c-e9408ba7cec9.png) 6 | 7 | ## Cheat Sheet - 2 8 | ![image](https://user-images.githubusercontent.com/5618143/204025676-0a94fec8-07fb-44f0-865f-4741ed5cf5fb.png) 9 | 10 | ## Cheat Sheet - 3 11 | ![image](https://user-images.githubusercontent.com/5618143/204025733-b7910d7e-cc0e-4114-888c-dcedef8a0747.png) 12 | 13 | ## Cheat Sheet - 4 14 | ![image](https://user-images.githubusercontent.com/5618143/204025779-f8fe1704-9df7-42be-996c-6583c86da961.png) 15 | -------------------------------------------------------------------------------- /resources/cheatsheets.md: -------------------------------------------------------------------------------- 1 | 2 | # Python Cheatsheets: 3 | 4 | ![image](https://user-images.githubusercontent.com/5618143/201534448-bc05bbb6-abc3-4c10-95fe-5d7403aba545.png) 5 | 6 | 7 | ![image](https://user-images.githubusercontent.com/5618143/201534325-ae0df0d8-7129-43b8-a3bb-0100efce5285.png) 8 | 9 | 10 | ![image](https://user-images.githubusercontent.com/5618143/201534338-cc2826d9-18ac-4d03-9cd8-6038f80db9f5.png) 11 | 12 | ![image](https://user-images.githubusercontent.com/5618143/201534346-fbfb3149-118e-4593-adbb-16f7742d6f8f.png) 13 | 14 | ![image](https://user-images.githubusercontent.com/5618143/201534357-a55814c1-d668-4d10-8e18-bf925cf430a4.png) 15 | -------------------------------------------------------------------------------- /resources/index.md: -------------------------------------------------------------------------------- 1 | # Awesome Free Resources for learning Python, Data science and Machine Learning 2 | 3 | ### Free Google Certification Courses 4 | - [Learn Python basics for Data Analysis](https://learndigital.withgoogle.com/digitalunlocked/course/learn-python-basics-for-data-analysis) 5 | - [Data Science Foundations](https://t.co/Dz2Xm2lC7k) 6 | - [Data Science with Python](https://t.co/ATJvro8Ktk) 7 | - [Machine Learning Crash Course](https://learndigital.withgoogle.com/digitalunlocked/course/machine-learning-crash-course) 8 | - [Intro to TensorFlow for Deep Learning](https://learndigital.withgoogle.com/digitalunlocked/course/intro-to-tensorflow-for-deep-learning) 9 | 10 | 11 | ### Become a Microsoft Certified AI Engineer for FREE 12 | - [Links](https://twitter.com/python_spaces/status/1580240522756886528) 13 | 14 | ### Free Data Analyst Courses 15 | - [IBM Data Analyst Professional Certificate](https://www.coursera.org/professional-certificates/ibm-data-analyst?irclickid=QzTTwr0zmxyNTusT-Tw62Ty2UkDQ8OX1q1rDUk0&irgwc=1&utm_medium=partners&utm_source=impact&utm_campaign=2624140&utm_content=b2c) 16 | - [Google Data Analytics Professional Certificate](https://www.coursera.org/professional-certificates/google-data-analytics?irclickid=QzTTwr0zmxyNTusT-Tw62Ty2UkDQ8IzZq1rDUk0&irgwc=1&utm_medium=partners&utm_source=impact&utm_campaign=2624140&utm_content=b2c) 17 | 18 | 19 | ### Google Sponsored Python Courses for FREE 20 | 1. Introduction to Python Programming 21 | https://learndigital.withgoogle.com/digitalunlocked/course/introduction-to-python-programming 22 | 2. Programming for Everybody (Getting Started with Python) 23 | https://learndigital.withgoogle.com/digitalunlocked/course/programming-for-everybody-python 24 | 3. Python Basics 25 | https://learndigital.withgoogle.com/digitalunlocked/course/python-basics 26 | 27 | 28 | ### Hadoop Fundamentals by IBM 29 | 30 | ![image](https://user-images.githubusercontent.com/5618143/198836602-6320951d-db99-4319-9d07-7b4eaaff442b.png) 31 | 32 | [Learning Path Link](https://cognitiveclass.ai/learn/hadoop) 33 | 34 | ### Computer Science to AI by Standford for FREE 35 | 36 | 1. [CS 101](https://t.co/24FTtaqdAE) 37 | 2. [Machine Learning Specialization](https://t.co/YtMJEeKbBz) 38 | 3. [Game Theory](https://t.co/7m8Ld134Hm) 39 | 4. [Designing Your Career](https://t.co/9SYhiWbkEc) 40 | 5. [Artificial Intelligence for Robotics](https://t.co/VmsnkOX0ao) 41 | -------------------------------------------------------------------------------- /streamlit_apps/101/README.md: -------------------------------------------------------------------------------- 1 | ## Simple Streamlit App 2 | 3 | 1. Required Python modules 4 | ``` 5 | pandas 6 | streamlit 7 | altair 8 | ``` 9 | 3. Run the app 10 | `streamlit run app.py` 11 | -------------------------------------------------------------------------------- /streamlit_apps/101/app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import pandas as pd 3 | import altair as alt 4 | 5 | # Read data from CSV file 6 | df = pd.read_csv("stock_prices.csv") 7 | 8 | # Filter data by stock name 9 | def filter_data(stock_name): 10 | return df[df["Stock"] == stock_name] 11 | 12 | # Create bar chart 13 | def create_bar_chart(stock_name): 14 | data = filter_data(stock_name) 15 | chart = alt.Chart(data).mark_bar().encode( 16 | x=alt.X("Date:T", axis=alt.Axis(title="Date")), 17 | y=alt.Y("Close:Q", axis=alt.Axis(title="Closing Price")), 18 | color=alt.Color("Stock:N", legend=alt.Legend(title="Stock")) 19 | ).properties(width=600, height=400, title=f"{stock_name} Closing Prices (Bar Chart)") 20 | return chart 21 | 22 | # Create line chart 23 | def create_line_chart(stock_name): 24 | data = filter_data(stock_name) 25 | chart = alt.Chart(data).mark_line().encode( 26 | x=alt.X("Date:T", axis=alt.Axis(title="Date")), 27 | y=alt.Y("Close:Q", axis=alt.Axis(title="Closing Price")), 28 | color=alt.Color("Stock:N", legend=alt.Legend(title="Stock")) 29 | ).properties(width=600, height=400, title=f"{stock_name} Closing Prices (Line Chart)") 30 | return chart 31 | 32 | # Streamlit app 33 | def main(): 34 | st.title("Apple and Tesla Stock Prices") 35 | stock_names = ["Apple", "Tesla"] 36 | stock_name = st.sidebar.selectbox("Select a stock", stock_names) 37 | chart_type = st.sidebar.radio("Select a chart type", ["Bar Chart", "Line Chart"]) 38 | if chart_type == "Bar Chart": 39 | chart = create_bar_chart(stock_name) 40 | else: 41 | chart = create_line_chart(stock_name) 42 | st.altair_chart(chart, use_container_width=True) 43 | 44 | if __name__ == "__main__": 45 | main() 46 | -------------------------------------------------------------------------------- /tips/audio_book.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/tips/audio_book.mp3 -------------------------------------------------------------------------------- /tips/first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/tips/first.png -------------------------------------------------------------------------------- /tips/py_notes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "412d8ff3-3aa5-4f40-a1a2-b16a0c38d5f8", 6 | "metadata": {}, 7 | "source": [ 8 | "# Advanced Python Tutorials" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "a1858955-8214-4f02-ade6-166cdd226240", 14 | "metadata": {}, 15 | "source": [ 16 | "### 1. NamedTuples" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 2, 22 | "id": "66d20a16-5dcf-47d0-8ace-bfc9d76eee3c", 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "# 💡 Python Tip 1: NamedTuples \n", 27 | "\n", 28 | "# 🟡 Let's define a student tuple with name, standard-section and marks\n", 29 | "student = ('Afiz', '5-A', 80)\n", 30 | "\n", 31 | "# The problem with tuples is, we had to remember the position of each item\n", 32 | "# Example: 0 for name, 2 for marks\n", 33 | "\n", 34 | "# ✅ NamedTuples allow us to access items using names instead of the position\n", 35 | "# Here is the example 👇\n", 36 | "\n", 37 | "from typing import NamedTuple\n", 38 | "\n", 39 | "class Student(NamedTuple):\n", 40 | " name: str\n", 41 | " standard: str\n", 42 | " marks: int" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "id": "7308f84d-abb6-45d9-9685-f7b814549776", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "s = Student('Rayan', '1-B', 90)" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "id": "40db2835-ced6-4812-98fd-93e527fcfd59", 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "data": { 63 | "text/plain": [ 64 | "'Rayan'" 65 | ] 66 | }, 67 | "execution_count": 4, 68 | "metadata": {}, 69 | "output_type": "execute_result" 70 | } 71 | ], 72 | "source": [ 73 | "s.name" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "id": "a54122c0-6da4-4926-969e-d53dc4f542c8", 79 | "metadata": {}, 80 | "source": [ 81 | "### 2. Special Characters " 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 1, 87 | "id": "7443ed93-601c-41dc-82ce-886828061cf2", 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [ 91 | "π = 22 /7" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 2, 97 | "id": "7d17d714-eb47-4e96-b25f-927b7b6e7fdf", 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "3.142857142857143\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "print(π)" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "id": "0d17dd0e-2d9a-4ec6-bc6e-f76d2814df45", 115 | "metadata": {}, 116 | "source": [ 117 | "### 3. Partition Method " 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 2, 123 | "id": "3a573716-13d0-4aeb-8e2f-c1804ce16831", 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "heading = \"Advanced Python Tutorial by Afiz\"\n", 128 | "title, _ , author = heading.partition('by ')" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 3, 134 | "id": "d5682dd4-2b98-4f25-8924-f59911a5eda1", 135 | "metadata": {}, 136 | "outputs": [ 137 | { 138 | "data": { 139 | "text/plain": [ 140 | "'Advanced Python Tutorial '" 141 | ] 142 | }, 143 | "execution_count": 3, 144 | "metadata": {}, 145 | "output_type": "execute_result" 146 | } 147 | ], 148 | "source": [ 149 | "title" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 4, 155 | "id": "64ea26e6-a68f-45d2-b2ea-61f22d833aa2", 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "data": { 160 | "text/plain": [ 161 | "'Afiz'" 162 | ] 163 | }, 164 | "execution_count": 4, 165 | "metadata": {}, 166 | "output_type": "execute_result" 167 | } 168 | ], 169 | "source": [ 170 | "author" 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "id": "eeb76c41-1d1d-4e7f-b1bf-eb2b711c7577", 176 | "metadata": {}, 177 | "source": [ 178 | "### 4. format_map method " 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 1, 184 | "id": "5c6cd4d1-77c0-4221-b6ff-241265bd98ee", 185 | "metadata": {}, 186 | "outputs": [ 187 | { 188 | "data": { 189 | "text/plain": [ 190 | "'Afiz - itsafiz - 1500'" 191 | ] 192 | }, 193 | "execution_count": 1, 194 | "metadata": {}, 195 | "output_type": "execute_result" 196 | } 197 | ], 198 | "source": [ 199 | "account = {'name': 'Afiz', 'id': 'itsafiz', 'followers': 1500}\n", 200 | "account_1 = {'name': 'Afiz Shaik', 'id': 'afizshaik', 'followers': 1500}\n", 201 | "\n", 202 | "'{name:10s} - {id:10s} - {followers:10d}'.format_map(account)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "id": "05fb50a0-27f5-40a6-90f7-2ff53c1d514e", 208 | "metadata": {}, 209 | "source": [ 210 | "### 5. wifi Password as QR using Python" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 1, 216 | "id": "5bbe49e6-7d25-4078-b039-3d77259b325f", 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "name": "stdout", 221 | "output_type": "stream", 222 | "text": [ 223 | "\u001b[33mWARNING: You are using pip version 21.3.1; however, version 22.2.2 is available.\n", 224 | "You should consider upgrading via the '/home/studio-lab-user/.conda/envs/default/bin/python -m pip install --upgrade pip' command.\u001b[0m\n" 225 | ] 226 | } 227 | ], 228 | "source": [ 229 | "!pip install wifi-qrcode-generator -q" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": 2, 235 | "id": "31d65c8a-1293-40b8-8bcd-13cc9efb5d57", 236 | "metadata": {}, 237 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plain": [ 242 | "" 243 | ] 244 | }, 245 | "execution_count": 2, 246 | "metadata": {}, 247 | "output_type": "execute_result" 248 | } 249 | ], 250 | "source": [ 251 | "import wifi_qrcode_generator as qr\n", 252 | "qr.wifi_qrcode('HelloWorld', False, 'WPA', 'Password')" 253 | ] 254 | }, 255 | { 256 | "cell_type": "markdown", 257 | "id": "9192714d-9707-4a1c-bbb6-fab40a3228ae", 258 | "metadata": {}, 259 | "source": [ 260 | "### 6. `__del__` magic method\n", 261 | "\n", 262 | "The `__del__()` method is a known as a destructor method. \n", 263 | "It is called when an object is garbage collected which happens \n", 264 | "after all references to the object have been deleted. \n", 265 | "\n", 266 | "\n", 267 | "coming to problem, if you run this code in jupyter notebook or \n", 268 | "Interactive mode(REPL), NOTHING gets printed, because session is \n", 269 | "active and none of objects are garbage collected. \n", 270 | "\n", 271 | "🟡 Example 👇 " 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": 1, 277 | "id": "7550f4c4-5bce-468d-8a5b-cad024778a4a", 278 | "metadata": {}, 279 | "outputs": [], 280 | "source": [ 281 | "class Spam:\n", 282 | " def __del__(self):\n", 283 | " print('Deleted')\n", 284 | "\n", 285 | "x = Spam()\n", 286 | "y = x\n", 287 | "del y" 288 | ] 289 | }, 290 | { 291 | "cell_type": "markdown", 292 | "id": "37b158b0-b01f-4228-8e02-c353a2596cdb", 293 | "metadata": {}, 294 | "source": [ 295 | "You might be thinking, how can we get **Deleted** message. \n", 296 | " \n", 297 | "There are two ways \n", 298 | "1. Run the code as program \n", 299 | "2. Create a function\n", 300 | "\n", 301 | "I will show you the 2nd method 👇\n" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 2, 307 | "id": "6803693d-6eb1-402b-9ce0-e2e19845ba01", 308 | "metadata": {}, 309 | "outputs": [ 310 | { 311 | "name": "stdout", 312 | "output_type": "stream", 313 | "text": [ 314 | "Deleted\n" 315 | ] 316 | } 317 | ], 318 | "source": [ 319 | "def hello():\n", 320 | " x = Spam()\n", 321 | "\n", 322 | "hello()" 323 | ] 324 | }, 325 | { 326 | "cell_type": "markdown", 327 | "id": "497de399-a21e-40d7-aaba-c56552d05652", 328 | "metadata": {}, 329 | "source": [ 330 | "✅ You might have noticed I didn't even called del 😂 \n", 331 | "I hope you got the point. If you like what you see. \n", 332 | "\n", 333 | "follow me at @itsafiz\n", 334 | "\n", 335 | "Cheers 🎉" 336 | ] 337 | }, 338 | { 339 | "cell_type": "markdown", 340 | "id": "0f32eea8-ebb8-4993-b8a5-7cfb9d7d489f", 341 | "metadata": {}, 342 | "source": [ 343 | "### 7. `__del__` method with two objects of same name\n", 344 | "\n", 345 | "\n", 346 | "The `__del__()` method is a known as a destructor method. \n", 347 | "It is called when an object is garbage collected which happens \n", 348 | "after all references to the object have been deleted. \n", 349 | "\n", 350 | "\n", 351 | "Coming to the problem, \n", 352 | "\n", 353 | "1️⃣ if you run this code in jupyter notebook or \n", 354 | "Interactive mode(REPL), **Deleted** is printed once. \n", 355 | "\n", 356 | "Here is the explanation 👇 \n", 357 | "\n", 358 | "1. `x = Spam()` # creates the object of Spam \n", 359 | "2. `x = Spam() ` # since there are reference to X, **Deleted** printed \n", 360 | "\n", 361 | "\n", 362 | "2️⃣ If you run this code as script, **Deleted** gets printed twice as \n", 363 | "two objects are created. \n", 364 | " " 365 | ] 366 | }, 367 | { 368 | "cell_type": "code", 369 | "execution_count": 1, 370 | "id": "be2497a7-5c4f-47be-b68e-9aa572684768", 371 | "metadata": {}, 372 | "outputs": [ 373 | { 374 | "name": "stdout", 375 | "output_type": "stream", 376 | "text": [ 377 | "Deleted\n" 378 | ] 379 | } 380 | ], 381 | "source": [ 382 | "class Spam:\n", 383 | " def __del__(self):\n", 384 | " print('Deleted')\n", 385 | "\n", 386 | "x = Spam()\n", 387 | "x = Spam()" 388 | ] 389 | }, 390 | { 391 | "cell_type": "code", 392 | "execution_count": null, 393 | "id": "c6d0b71c-9541-41de-82b4-a89582f77f72", 394 | "metadata": {}, 395 | "outputs": [], 396 | "source": [] 397 | } 398 | ], 399 | "metadata": { 400 | "kernelspec": { 401 | "display_name": "default:Python", 402 | "language": "python", 403 | "name": "conda-env-default-py" 404 | }, 405 | "language_info": { 406 | "codemirror_mode": { 407 | "name": "ipython", 408 | "version": 3 409 | }, 410 | "file_extension": ".py", 411 | "mimetype": "text/x-python", 412 | "name": "python", 413 | "nbconvert_exporter": "python", 414 | "pygments_lexer": "ipython3", 415 | "version": "3.9.12" 416 | } 417 | }, 418 | "nbformat": 4, 419 | "nbformat_minor": 5 420 | } 421 | -------------------------------------------------------------------------------- /tips/python_tricks.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "9c8696f4-f0cb-47c7-99dc-10fd75230ce1", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "!pip install google -q" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 2, 16 | "id": "aa432ec6-4d12-400c-8fe1-f0593916ae7d", 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "https://www.coursera.org/courses?query=free%20courses%20data%20science\n", 24 | "https://medium.com/javarevisited/10-free-data-science-online-courses-for-beginners-a5fe78c2cb7b\n", 25 | "https://www.udacity.com/course/intro-to-data-science--ud359\n", 26 | "https://www.mygreatlearning.com/data-science/free-courses\n", 27 | "https://www.simplilearn.com/data-science-free-course-for-beginners-skillup\n", 28 | "https://www.simplilearn.com/data-science-free-courses-article\n", 29 | "https://www.edx.org/learn/data-science\n", 30 | "https://www.edx.org/learn/data-analysis\n", 31 | "https://pll.harvard.edu/subject/data-science\n", 32 | "https://careerfoundry.com/en/blog/data-analytics/free-data-analytics-courses/\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "from googlesearch import search\n", 38 | "query = \"Free Data Science courses\"\n", 39 | "for result in search(query, num=10, stop=10, pause=5):\n", 40 | " print(result)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 3, 46 | "id": "6004bf9a-89b1-4d8f-a4ca-3151d469872c", 47 | "metadata": {}, 48 | "outputs": [ 49 | { 50 | "name": "stdout", 51 | "output_type": "stream", 52 | "text": [ 53 | "https://www.onsightapp.com/blog/youtube-tech-channels\n", 54 | "https://wethegeek.com/best-tech-channels-on-youtube/\n", 55 | "https://www.techgeek360.com/top-10-tech-youtubers-in-the-world/\n", 56 | "https://www.techgeek360.com/top-10-tech-youtubers-in-the-world/#Top_10_Tech_Youtubers_in_The_World\n", 57 | "https://www.techgeek360.com/top-10-tech-youtubers-in-the-world/#2_Mrwhosetheboss\n", 58 | "https://www.techgeek360.com/top-10-tech-youtubers-in-the-world/#4_Linus_Tech_Tips\n", 59 | "https://www.techgeek360.com/top-10-tech-youtubers-in-the-world/#5_Austin_Evans\n", 60 | "https://blog.bit.ai/top-tech-youtubers/\n", 61 | "https://blog.feedspot.com/technology_youtube_channels/\n", 62 | "https://blog.feedspot.com/technology_youtube_channels/#rssfsbhead\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "query = \"Top 10 Tech YouTube channels\"\n", 68 | "for result in search(query, num=10, stop=10, pause=5):\n", 69 | " print(result)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "id": "43138366-9ee9-4d47-b6f0-15ea3cf92709", 75 | "metadata": {}, 76 | "source": [ 77 | "## URL shortener" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 4, 83 | "id": "6e317d7d-5e8a-4f8d-b00a-f8aa91675e74", 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "!pip install pyshorteners -q" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 7, 93 | "id": "ec72fb38-85a1-4897-8010-2cba5f7e7b3d", 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "data": { 98 | "text/plain": [ 99 | "'https://tinyurl.com/2zftnjkz'" 100 | ] 101 | }, 102 | "execution_count": 7, 103 | "metadata": {}, 104 | "output_type": "execute_result" 105 | } 106 | ], 107 | "source": [ 108 | "from pyshorteners import Shortener\n", 109 | "\n", 110 | "Shortener().tinyurl.short(\"https://twitter.com/itsafiz\")" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "id": "1d8aa60e-b333-4113-a892-32896f790530", 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [ 120 | "rom pyshorteners import Shortener\n", 121 | "\n", 122 | "Shortener().tinyurl.short(\"https://tweetdeck.twitter.com/\")" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "id": "64c13769-e606-4600-9e99-276fb2d02920", 128 | "metadata": {}, 129 | "source": [] 130 | } 131 | ], 132 | "metadata": { 133 | "kernelspec": { 134 | "display_name": "default:Python", 135 | "language": "python", 136 | "name": "conda-env-default-py" 137 | }, 138 | "language_info": { 139 | "codemirror_mode": { 140 | "name": "ipython", 141 | "version": 3 142 | }, 143 | "file_extension": ".py", 144 | "mimetype": "text/x-python", 145 | "name": "python", 146 | "nbconvert_exporter": "python", 147 | "pygments_lexer": "ipython3", 148 | "version": "3.9.12" 149 | } 150 | }, 151 | "nbformat": 4, 152 | "nbformat_minor": 5 153 | } 154 | -------------------------------------------------------------------------------- /tips/test_data/example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afizs/python-notes/32b5a2ab7ffe7ee4db24aa624cc6f083f0e421e0/tips/test_data/example.pdf -------------------------------------------------------------------------------- /webscrapping/quotes.csv: -------------------------------------------------------------------------------- 1 | Text,Author,Tags 2 | “The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.”,Albert Einstein,"change, deep-thoughts, thinking, world" 3 | "“It is our choices, Harry, that show what we truly are, far more than our abilities.”",J.K. Rowling,"abilities, choices" 4 | “There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.”,Albert Einstein,"inspirational, life, live, miracle, miracles" 5 | "“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.”",Jane Austen,"aliteracy, books, classic, humor" 6 | "“Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring.”",Marilyn Monroe,"be-yourself, inspirational" 7 | “Try not to become a man of success. Rather become a man of value.”,Albert Einstein,"adulthood, success, value" 8 | “It is better to be hated for what you are than to be loved for what you are not.”,André Gide,"life, love" 9 | "“I have not failed. I've just found 10,000 ways that won't work.”",Thomas A. Edison,"edison, failure, inspirational, paraphrased" 10 | “A woman is like a tea bag; you never know how strong it is until it's in hot water.”,Eleanor Roosevelt,misattributed-eleanor-roosevelt 11 | "“A day without sunshine is like, you know, night.”",Steve Martin,"humor, obvious, simile" 12 | "“This life is what you make it. No matter what, you're going to mess up sometimes, it's a universal truth. But the good part is you get to decide how you're going to mess it up. Girls will be your friends - they'll act like it anyway. But just remember, some come, some go. The ones that stay with you through everything - they're your true best friends. Don't let go of them. Also remember, sisters make the best friends in the world. As for lovers, well, they'll come and go too. And baby, I hate to say it, most of them - actually pretty much all of them are going to break your heart, but you can't give up because if you give up, you'll never find your soulmate. You'll never find that half who makes you whole and that goes for everything. Just because you fail once, doesn't mean you're gonna fail at everything. Keep trying, hold on, and always, always, always believe in yourself, because if you don't, then who will, sweetie? So keep your head high, keep your chin up, and most importantly, keep smiling, because life's a beautiful thing and there's so much to smile about.”",Marilyn Monroe,"friends, heartbreak, inspirational, life, love, sisters" 13 | "“It takes a great deal of bravery to stand up to our enemies, but just as much to stand up to our friends.”",J.K. Rowling,"courage, friends" 14 | "“If you can't explain it to a six year old, you don't understand it yourself.”",Albert Einstein,"simplicity, understand" 15 | "“You may not be her first, her last, or her only. She loved before she may love again. But if she loves you now, what else matters? She's not perfect—you aren't either, and the two of you may never be perfect together but if she can make you laugh, cause you to think twice, and admit to being human and making mistakes, hold onto her and give her the most you can. She may not be thinking about you every second of the day, but she will give you a part of her that she knows you can break—her heart. So don't hurt her, don't change her, don't analyze and don't expect more than she can give. Smile when she makes you happy, let her know when she makes you mad, and miss her when she's not there.”",Bob Marley,love 16 | "“I like nonsense, it wakes up the brain cells. Fantasy is a necessary ingredient in living.”",Dr. Seuss,fantasy 17 | "“I may not have gone where I intended to go, but I think I have ended up where I needed to be.”",Douglas Adams,"life, navigation" 18 | "“The opposite of love is not hate, it's indifference. The opposite of art is not ugliness, it's indifference. The opposite of faith is not heresy, it's indifference. And the opposite of life is not death, it's indifference.”",Elie Wiesel,"activism, apathy, hate, indifference, inspirational, love, opposite, philosophy" 19 | "“It is not a lack of love, but a lack of friendship that makes unhappy marriages.”",Friedrich Nietzsche,"friendship, lack-of-friendship, lack-of-love, love, marriage, unhappy-marriage" 20 | "“Good friends, good books, and a sleepy conscience: this is the ideal life.”",Mark Twain,"books, contentment, friends, friendship, life" 21 | “Life is what happens to us while we are making other plans.”,Allen Saunders,"fate, life, misattributed-john-lennon, planning, plans" 22 | "“I love you without knowing how, or when, or from where. I love you simply, without problems or pride: I love you in this way because I do not know any other way of loving but this, in which there is no I or you, so intimate that your hand upon my chest is my hand, so intimate that when I fall asleep your eyes close.”",Pablo Neruda,"love, poetry" 23 | “For every minute you are angry you lose sixty seconds of happiness.”,Ralph Waldo Emerson,happiness 24 | "“If you judge people, you have no time to love them.”",Mother Teresa,attributed-no-source 25 | “Anyone who thinks sitting in church can make you a Christian must also think that sitting in a garage can make you a car.”,Garrison Keillor,"humor, religion" 26 | “Beauty is in the eye of the beholder and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.”,Jim Henson,humor 27 | "“Today you are You, that is truer than true. There is no one alive who is Youer than You.”",Dr. Seuss,"comedy, life, yourself" 28 | "“If you want your children to be intelligent, read them fairy tales. If you want them to be more intelligent, read them more fairy tales.”",Albert Einstein,"children, fairy-tales" 29 | "“It is impossible to live without failing at something, unless you live so cautiously that you might as well not have lived at all - in which case, you fail by default.”",J.K. Rowling, 30 | “Logic will get you from A to Z; imagination will get you everywhere.”,Albert Einstein,imagination 31 | "“One good thing about music, when it hits you, you feel no pain.”",Bob Marley,music 32 | "“The more that you read, the more things you will know. The more that you learn, the more places you'll go.”",Dr. Seuss,"learning, reading, seuss" 33 | "“Of course it is happening inside your head, Harry, but why on earth should that mean that it is not real?”",J.K. Rowling,dumbledore 34 | "“The truth is, everyone is going to hurt you. You just got to find the ones worth suffering for.”",Bob Marley,friendship 35 | “Not all of us can do great things. But we can do small things with great love.”,Mother Teresa,"misattributed-to-mother-teresa, paraphrased" 36 | "“To the well-organized mind, death is but the next great adventure.”",J.K. Rowling,"death, inspirational" 37 | “All you need is love. But a little chocolate now and then doesn't hurt.”,Charles M. Schulz,"chocolate, food, humor" 38 | “We read to know we're not alone.”,William Nicholson,"misattributed-to-c-s-lewis, reading" 39 | “Any fool can know. The point is to understand.”,Albert Einstein,"knowledge, learning, understanding, wisdom" 40 | “I have always imagined that Paradise will be a kind of library.”,Jorge Luis Borges,"books, library" 41 | “It is never too late to be what you might have been.”,George Eliot,inspirational 42 | "“A reader lives a thousand lives before he dies, said Jojen. The man who never reads lives only one.”",George R.R. Martin,"read, readers, reading, reading-books" 43 | “You can never get a cup of tea large enough or a book long enough to suit me.”,C.S. Lewis,"books, inspirational, reading, tea" 44 | “You believe lies so you eventually learn to trust no one but yourself.”,Marilyn Monroe, 45 | "“If you can make a woman laugh, you can make her do anything.”",Marilyn Monroe,"girls, love" 46 | "“Life is like riding a bicycle. To keep your balance, you must keep moving.”",Albert Einstein,"life, simile" 47 | “The real lover is the man who can thrill you by kissing your forehead or smiling into your eyes or just staring into space.”,Marilyn Monroe,love 48 | "“A wise girl kisses but doesn't love, listens but doesn't believe, and leaves before she is left.”",Marilyn Monroe,attributed-no-source 49 | “Only in the darkness can you see the stars.”,Martin Luther King Jr.,"hope, inspirational" 50 | "“It matters not what someone is born, but what they grow to be.”",J.K. Rowling,dumbledore 51 | "“Love does not begin and end the way we seem to think it does. Love is a battle, love is a war; love is a growing up.”",James Baldwin,love 52 | "“There is nothing I would not do for those who are really my friends. I have no notion of loving people by halves, it is not my nature.”",Jane Austen,"friendship, love" 53 | “Do one thing every day that scares you.”,Eleanor Roosevelt,"attributed, fear, inspiration" 54 | "“I am good, but not an angel. I do sin, but I am not the devil. I am just a small girl in a big world trying to find someone to love.”",Marilyn Monroe,attributed-no-source 55 | "“If I were not a physicist, I would probably be a musician. I often think in music. I live my daydreams in music. I see my life in terms of music.”",Albert Einstein,music 56 | "“If you only read the books that everyone else is reading, you can only think what everyone else is thinking.”",Haruki Murakami,"books, thought" 57 | “The difference between genius and stupidity is: genius has its limits.”,Alexandre Dumas fils,misattributed-to-einstein 58 | "“He's like a drug for you, Bella.”",Stephenie Meyer,"drug, romance, simile" 59 | “There is no friend as loyal as a book.”,Ernest Hemingway,"books, friends, novelist-quotes" 60 | "“When one door of happiness closes, another opens; but often we look so long at the closed door that we do not see the one which has been opened for us.”",Helen Keller,inspirational 61 | “Life isn't about finding yourself. Life is about creating yourself.”,George Bernard Shaw,"inspirational, life, yourself" 62 | "“That's the problem with drinking, I thought, as I poured myself a drink. If something bad happens you drink in an attempt to forget; if something good happens you drink in order to celebrate; and if nothing happens you drink to make something happen.”",Charles Bukowski,alcohol 63 | “You don’t forget the face of the person who was your last hope.”,Suzanne Collins,the-hunger-games 64 | "“Remember, we're madly in love, so it's all right to kiss me anytime you feel like it.”",Suzanne Collins,humor 65 | "“To love at all is to be vulnerable. Love anything and your heart will be wrung and possibly broken. If you want to make sure of keeping it intact you must give it to no one, not even an animal. Wrap it carefully round with hobbies and little luxuries; avoid all entanglements. Lock it up safe in the casket or coffin of your selfishness. But in that casket, safe, dark, motionless, airless, it will change. It will not be broken; it will become unbreakable, impenetrable, irredeemable. To love is to be vulnerable.”",C.S. Lewis,love 66 | “Not all those who wander are lost.”,J.R.R. Tolkien,"bilbo, journey, lost, quest, travel, wander" 67 | "“Do not pity the dead, Harry. Pity the living, and, above all those who live without love.”",J.K. Rowling,live-death-love 68 | “There is nothing to writing. All you do is sit down at a typewriter and bleed.”,Ernest Hemingway,"good, writing" 69 | “Finish each day and be done with it. You have done what you could. Some blunders and absurdities no doubt crept in; forget them as soon as you can. Tomorrow is a new day. You shall begin it serenely and with too high a spirit to be encumbered with your old nonsense.”,Ralph Waldo Emerson,"life, regrets" 70 | “I have never let my schooling interfere with my education.”,Mark Twain,education 71 | “I have heard there are troubles of more than one kind. Some come from ahead and some come from behind. But I've bought a big bat. I'm all ready you see. Now my troubles are going to have troubles with me!”,Dr. Seuss,troubles 72 | “If I had a flower for every time I thought of you...I could walk through my garden forever.”,Alfred Tennyson,"friendship, love" 73 | “Some people never go crazy. What truly horrible lives they must lead.”,Charles Bukowski,humor 74 | "“The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.”",Terry Pratchett,"humor, open-mind, thinking" 75 | "“Think left and think right and think low and think high. Oh, the thinks you can think up if only you try!”",Dr. Seuss,"humor, philosophy" 76 | "“What really knocks me out is a book that, when you're all done reading it, you wish the author that wrote it was a terrific friend of yours and you could call him up on the phone whenever you felt like it. That doesn't happen much, though.”",J.D. Salinger,"authors, books, literature, reading, writing" 77 | “The reason I talk to myself is because I’m the only one whose answers I accept.”,George Carlin,"humor, insanity, lies, lying, self-indulgence, truth" 78 | "“You may say I'm a dreamer, but I'm not the only one. I hope someday you'll join us. And the world will live as one.”",John Lennon,"beatles, connection, dreamers, dreaming, dreams, hope, inspirational, peace" 79 | “I am free of all prejudice. I hate everyone equally. ”,W.C. Fields,"humor, sinister" 80 | “The question isn't who is going to let me; it's who is going to stop me.”,Ayn Rand, 81 | “′Classic′ - a book which people praise and don't read.”,Mark Twain,"books, classic, reading" 82 | “Anyone who has never made a mistake has never tried anything new.”,Albert Einstein,mistakes 83 | "“A lady's imagination is very rapid; it jumps from admiration to love, from love to matrimony in a moment.”",Jane Austen,"humor, love, romantic, women" 84 | "“Remember, if the time should come when you have to make a choice between what is right and what is easy, remember what happened to a boy who was good, and kind, and brave, because he strayed across the path of Lord Voldemort. Remember Cedric Diggory.”",J.K. Rowling,integrity 85 | "“I declare after all there is no enjoyment like reading! How much sooner one tires of any thing than of a book! -- When I have a house of my own, I shall be miserable if I have not an excellent library.”",Jane Austen,"books, library, reading" 86 | "“There are few people whom I really love, and still fewer of whom I think well. The more I see of the world, the more am I dissatisfied with it; and every day confirms my belief of the inconsistency of all human characters, and of the little dependence that can be placed on the appearance of merit or sense.”",Jane Austen,"elizabeth-bennet, jane-austen" 87 | “Some day you will be old enough to start reading fairy tales again.”,C.S. Lewis,"age, fairytales, growing-up" 88 | “We are not necessarily doubting that God will do the best for us; we are wondering how painful the best will turn out to be.”,C.S. Lewis,god 89 | “The fear of death follows from the fear of life. A man who lives fully is prepared to die at any time.”,Mark Twain,"death, life" 90 | “A lie can travel half way around the world while the truth is putting on its shoes.”,Mark Twain,"misattributed-mark-twain, truth" 91 | "“I believe in Christianity as I believe that the sun has risen: not only because I see it, but because by it I see everything else.”",C.S. Lewis,"christianity, faith, religion, sun" 92 | "“The truth."" Dumbledore sighed. ""It is a beautiful and terrible thing, and should therefore be treated with great caution.”",J.K. Rowling,truth 93 | "“I'm the one that's got to die when it's time for me to die, so let me live my life the way I want to.”",Jimi Hendrix,"death, life" 94 | “To die will be an awfully big adventure.”,J.M. Barrie,"adventure, love" 95 | “It takes courage to grow up and become who you really are.”,E.E. Cummings,courage 96 | “But better to get hurt by the truth than comforted with a lie.”,Khaled Hosseini,life 97 | “You never really understand a person until you consider things from his point of view... Until you climb inside of his skin and walk around in it.”,Harper Lee,better-life-empathy 98 | "“You have to write the book that wants to be written. And if the book will be too difficult for grown-ups, then you write it for children.”",Madeleine L'Engle,"books, children, difficult, grown-ups, write, writers, writing" 99 | “Never tell the truth to people who are not worthy of it.”,Mark Twain,truth 100 | "“A person's a person, no matter how small.”",Dr. Seuss,inspirational 101 | "“... a mind needs books as a sword needs a whetstone, if it is to keep its edge.”",George R.R. Martin,"books, mind" 102 | -------------------------------------------------------------------------------- /webscrapping/quotes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "2e0aeb7e-23a4-4b65-af78-88c2d0b6b514", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "def scrape_page(soup, quotes):\n", 11 | " # retrieving all the quote
HTML element on the page\n", 12 | " quote_elements = soup.find_all('div', class_='quote')\n", 13 | "\n", 14 | " # iterating over the list of quote elements\n", 15 | " # to extract the data of interest and store it\n", 16 | " # in quotes\n", 17 | " for quote_element in quote_elements:\n", 18 | " # extracting the text of the quote\n", 19 | " text = quote_element.find('span', class_='text').text\n", 20 | " # extracting the author of the quote\n", 21 | " author = quote_element.find('small', class_='author').text\n", 22 | "\n", 23 | " # extracting the tag HTML elements related to the quote\n", 24 | " tag_elements = quote_element.find('div', class_='tags').find_all('a', class_='tag')\n", 25 | "\n", 26 | " # storing the list of tag strings in a list\n", 27 | " tags = []\n", 28 | " for tag_element in tag_elements:\n", 29 | " tags.append(tag_element.text)\n", 30 | "\n", 31 | " # appending a dictionary containing the quote data\n", 32 | " # in a new format in the quote list\n", 33 | " quotes.append(\n", 34 | " {\n", 35 | " 'text': text,\n", 36 | " 'author': author,\n", 37 | " 'tags': ', '.join(tags) # merging the tags into a \"A, B, ..., Z\" string\n", 38 | " }\n", 39 | " )" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "id": "21b36906-b292-4261-bce5-bdb781e08128", 45 | "metadata": {}, 46 | "source": [ 47 | "### Web scrapping with Python in simple steps" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 7, 53 | "id": "b8fedaca-0dc1-48e5-b4cf-fffaa28d805f", 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "import requests\n", 58 | "from bs4 import BeautifulSoup" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 8, 64 | "id": "778546e2-bef5-4071-9b5f-fac8bc747736", 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "# the url of the home page of the target website\n", 69 | "base_url = 'https://quotes.toscrape.com'\n", 70 | "\n", 71 | "# defining the User-Agent header to use in the GET request below\n", 72 | "headers = {\n", 73 | " 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'\n", 74 | "}\n", 75 | "\n", 76 | "# retrieving the target web page\n", 77 | "page = requests.get(base_url, headers=headers)\n", 78 | "\n", 79 | "# parsing the target web page with Beautiful Soup\n", 80 | "soup = BeautifulSoup(page.text, 'html.parser')\n", 81 | "\n", 82 | "# initializing the variable that will contain\n", 83 | "# the list of all quote data\n", 84 | "quotes = []\n", 85 | "\n", 86 | "# scraping the home page\n", 87 | "scrape_page(soup, quotes)\n", 88 | "\n", 89 | "# getting the \"Next →\" HTML element\n", 90 | "next_li_element = soup.find('li', class_='next')\n", 91 | "\n", 92 | "# if there is a next page to scrape\n", 93 | "while next_li_element is not None:\n", 94 | " next_page_relative_url = next_li_element.find('a', href=True)['href']\n", 95 | "\n", 96 | " # getting the new page\n", 97 | " page = requests.get(base_url + next_page_relative_url, headers=headers)\n", 98 | "\n", 99 | " # parsing the new page\n", 100 | " soup = BeautifulSoup(page.text, 'html.parser')\n", 101 | "\n", 102 | " # scraping the new page\n", 103 | " scrape_page(soup, quotes)\n", 104 | "\n", 105 | " # looking for the \"Next →\" HTML element in the new page\n", 106 | " next_li_element = soup.find('li', class_='next')" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 9, 112 | "id": "b4a46fb4-0a02-43bf-915a-6240bab314f0", 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "“The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.”\n", 120 | "“It is our choices, Harry, that show what we truly are, far more than our abilities.”\n", 121 | "“There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.”\n", 122 | "“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.”\n", 123 | "“Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring.”\n", 124 | "“Try not to become a man of success. Rather become a man of value.”\n", 125 | "“It is better to be hated for what you are than to be loved for what you are not.”\n", 126 | "“I have not failed. I've just found 10,000 ways that won't work.”\n", 127 | "“A woman is like a tea bag; you never know how strong it is until it's in hot water.”\n", 128 | "“A day without sunshine is like, you know, night.”\n", 129 | "“This life is what you make it. No matter what, you're going to mess up sometimes, it's a universal truth. But the good part is you get to decide how you're going to mess it up. Girls will be your friends - they'll act like it anyway. But just remember, some come, some go. The ones that stay with you through everything - they're your true best friends. Don't let go of them. Also remember, sisters make the best friends in the world. As for lovers, well, they'll come and go too. And baby, I hate to say it, most of them - actually pretty much all of them are going to break your heart, but you can't give up because if you give up, you'll never find your soulmate. You'll never find that half who makes you whole and that goes for everything. Just because you fail once, doesn't mean you're gonna fail at everything. Keep trying, hold on, and always, always, always believe in yourself, because if you don't, then who will, sweetie? So keep your head high, keep your chin up, and most importantly, keep smiling, because life's a beautiful thing and there's so much to smile about.”\n", 130 | "“It takes a great deal of bravery to stand up to our enemies, but just as much to stand up to our friends.”\n", 131 | "“If you can't explain it to a six year old, you don't understand it yourself.”\n", 132 | "“You may not be her first, her last, or her only. She loved before she may love again. But if she loves you now, what else matters? She's not perfect—you aren't either, and the two of you may never be perfect together but if she can make you laugh, cause you to think twice, and admit to being human and making mistakes, hold onto her and give her the most you can. She may not be thinking about you every second of the day, but she will give you a part of her that she knows you can break—her heart. So don't hurt her, don't change her, don't analyze and don't expect more than she can give. Smile when she makes you happy, let her know when she makes you mad, and miss her when she's not there.”\n", 133 | "“I like nonsense, it wakes up the brain cells. Fantasy is a necessary ingredient in living.”\n", 134 | "“I may not have gone where I intended to go, but I think I have ended up where I needed to be.”\n", 135 | "“The opposite of love is not hate, it's indifference. The opposite of art is not ugliness, it's indifference. The opposite of faith is not heresy, it's indifference. And the opposite of life is not death, it's indifference.”\n", 136 | "“It is not a lack of love, but a lack of friendship that makes unhappy marriages.”\n", 137 | "“Good friends, good books, and a sleepy conscience: this is the ideal life.”\n", 138 | "“Life is what happens to us while we are making other plans.”\n", 139 | "“I love you without knowing how, or when, or from where. I love you simply, without problems or pride: I love you in this way because I do not know any other way of loving but this, in which there is no I or you, so intimate that your hand upon my chest is my hand, so intimate that when I fall asleep your eyes close.”\n", 140 | "“For every minute you are angry you lose sixty seconds of happiness.”\n", 141 | "“If you judge people, you have no time to love them.”\n", 142 | "“Anyone who thinks sitting in church can make you a Christian must also think that sitting in a garage can make you a car.”\n", 143 | "“Beauty is in the eye of the beholder and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.”\n", 144 | "“Today you are You, that is truer than true. There is no one alive who is Youer than You.”\n", 145 | "“If you want your children to be intelligent, read them fairy tales. If you want them to be more intelligent, read them more fairy tales.”\n", 146 | "“It is impossible to live without failing at something, unless you live so cautiously that you might as well not have lived at all - in which case, you fail by default.”\n", 147 | "“Logic will get you from A to Z; imagination will get you everywhere.”\n", 148 | "“One good thing about music, when it hits you, you feel no pain.”\n", 149 | "“The more that you read, the more things you will know. The more that you learn, the more places you'll go.”\n", 150 | "“Of course it is happening inside your head, Harry, but why on earth should that mean that it is not real?”\n", 151 | "“The truth is, everyone is going to hurt you. You just got to find the ones worth suffering for.”\n", 152 | "“Not all of us can do great things. But we can do small things with great love.”\n", 153 | "“To the well-organized mind, death is but the next great adventure.”\n", 154 | "“All you need is love. But a little chocolate now and then doesn't hurt.”\n", 155 | "“We read to know we're not alone.”\n", 156 | "“Any fool can know. The point is to understand.”\n", 157 | "“I have always imagined that Paradise will be a kind of library.”\n", 158 | "“It is never too late to be what you might have been.”\n", 159 | "“A reader lives a thousand lives before he dies, said Jojen. The man who never reads lives only one.”\n", 160 | "“You can never get a cup of tea large enough or a book long enough to suit me.”\n", 161 | "“You believe lies so you eventually learn to trust no one but yourself.”\n", 162 | "“If you can make a woman laugh, you can make her do anything.”\n", 163 | "“Life is like riding a bicycle. To keep your balance, you must keep moving.”\n", 164 | "“The real lover is the man who can thrill you by kissing your forehead or smiling into your eyes or just staring into space.”\n", 165 | "“A wise girl kisses but doesn't love, listens but doesn't believe, and leaves before she is left.”\n", 166 | "“Only in the darkness can you see the stars.”\n", 167 | "“It matters not what someone is born, but what they grow to be.”\n", 168 | "“Love does not begin and end the way we seem to think it does. Love is a battle, love is a war; love is a growing up.”\n", 169 | "“There is nothing I would not do for those who are really my friends. I have no notion of loving people by halves, it is not my nature.”\n", 170 | "“Do one thing every day that scares you.”\n", 171 | "“I am good, but not an angel. I do sin, but I am not the devil. I am just a small girl in a big world trying to find someone to love.”\n", 172 | "“If I were not a physicist, I would probably be a musician. I often think in music. I live my daydreams in music. I see my life in terms of music.”\n", 173 | "“If you only read the books that everyone else is reading, you can only think what everyone else is thinking.”\n", 174 | "“The difference between genius and stupidity is: genius has its limits.”\n", 175 | "“He's like a drug for you, Bella.”\n", 176 | "“There is no friend as loyal as a book.”\n", 177 | "“When one door of happiness closes, another opens; but often we look so long at the closed door that we do not see the one which has been opened for us.”\n", 178 | "“Life isn't about finding yourself. Life is about creating yourself.”\n", 179 | "“That's the problem with drinking, I thought, as I poured myself a drink. If something bad happens you drink in an attempt to forget; if something good happens you drink in order to celebrate; and if nothing happens you drink to make something happen.”\n", 180 | "“You don’t forget the face of the person who was your last hope.”\n", 181 | "“Remember, we're madly in love, so it's all right to kiss me anytime you feel like it.”\n", 182 | "“To love at all is to be vulnerable. Love anything and your heart will be wrung and possibly broken. If you want to make sure of keeping it intact you must give it to no one, not even an animal. Wrap it carefully round with hobbies and little luxuries; avoid all entanglements. Lock it up safe in the casket or coffin of your selfishness. But in that casket, safe, dark, motionless, airless, it will change. It will not be broken; it will become unbreakable, impenetrable, irredeemable. To love is to be vulnerable.”\n", 183 | "“Not all those who wander are lost.”\n", 184 | "“Do not pity the dead, Harry. Pity the living, and, above all those who live without love.”\n", 185 | "“There is nothing to writing. All you do is sit down at a typewriter and bleed.”\n", 186 | "“Finish each day and be done with it. You have done what you could. Some blunders and absurdities no doubt crept in; forget them as soon as you can. Tomorrow is a new day. You shall begin it serenely and with too high a spirit to be encumbered with your old nonsense.”\n", 187 | "“I have never let my schooling interfere with my education.”\n", 188 | "“I have heard there are troubles of more than one kind. Some come from ahead and some come from behind. But I've bought a big bat. I'm all ready you see. Now my troubles are going to have troubles with me!”\n", 189 | "“If I had a flower for every time I thought of you...I could walk through my garden forever.”\n", 190 | "“Some people never go crazy. What truly horrible lives they must lead.”\n", 191 | "“The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.”\n", 192 | "“Think left and think right and think low and think high. Oh, the thinks you can think up if only you try!”\n", 193 | "“What really knocks me out is a book that, when you're all done reading it, you wish the author that wrote it was a terrific friend of yours and you could call him up on the phone whenever you felt like it. That doesn't happen much, though.”\n", 194 | "“The reason I talk to myself is because I’m the only one whose answers I accept.”\n", 195 | "“You may say I'm a dreamer, but I'm not the only one. I hope someday you'll join us. And the world will live as one.”\n", 196 | "“I am free of all prejudice. I hate everyone equally. ”\n", 197 | "“The question isn't who is going to let me; it's who is going to stop me.”\n", 198 | "“′Classic′ - a book which people praise and don't read.”\n", 199 | "“Anyone who has never made a mistake has never tried anything new.”\n", 200 | "“A lady's imagination is very rapid; it jumps from admiration to love, from love to matrimony in a moment.”\n", 201 | "“Remember, if the time should come when you have to make a choice between what is right and what is easy, remember what happened to a boy who was good, and kind, and brave, because he strayed across the path of Lord Voldemort. Remember Cedric Diggory.”\n", 202 | "“I declare after all there is no enjoyment like reading! How much sooner one tires of any thing than of a book! -- When I have a house of my own, I shall be miserable if I have not an excellent library.”\n", 203 | "“There are few people whom I really love, and still fewer of whom I think well. The more I see of the world, the more am I dissatisfied with it; and every day confirms my belief of the inconsistency of all human characters, and of the little dependence that can be placed on the appearance of merit or sense.”\n", 204 | "“Some day you will be old enough to start reading fairy tales again.”\n", 205 | "“We are not necessarily doubting that God will do the best for us; we are wondering how painful the best will turn out to be.”\n", 206 | "“The fear of death follows from the fear of life. A man who lives fully is prepared to die at any time.”\n", 207 | "“A lie can travel half way around the world while the truth is putting on its shoes.”\n", 208 | "“I believe in Christianity as I believe that the sun has risen: not only because I see it, but because by it I see everything else.”\n", 209 | "“The truth.\" Dumbledore sighed. \"It is a beautiful and terrible thing, and should therefore be treated with great caution.”\n", 210 | "“I'm the one that's got to die when it's time for me to die, so let me live my life the way I want to.”\n", 211 | "“To die will be an awfully big adventure.”\n", 212 | "“It takes courage to grow up and become who you really are.”\n", 213 | "“But better to get hurt by the truth than comforted with a lie.”\n", 214 | "“You never really understand a person until you consider things from his point of view... Until you climb inside of his skin and walk around in it.”\n", 215 | "“You have to write the book that wants to be written. And if the book will be too difficult for grown-ups, then you write it for children.”\n", 216 | "“Never tell the truth to people who are not worthy of it.”\n", 217 | "“A person's a person, no matter how small.”\n", 218 | "“... a mind needs books as a sword needs a whetstone, if it is to keep its edge.”\n" 219 | ] 220 | } 221 | ], 222 | "source": [ 223 | "for quote in quotes:\n", 224 | " print(quote['text'])" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": null, 230 | "id": "0fa1ea0b-274f-4915-a921-ff45b89c4a09", 231 | "metadata": {}, 232 | "outputs": [], 233 | "source": [] 234 | } 235 | ], 236 | "metadata": { 237 | "kernelspec": { 238 | "display_name": "default:Python", 239 | "language": "python", 240 | "name": "conda-env-default-py" 241 | }, 242 | "language_info": { 243 | "codemirror_mode": { 244 | "name": "ipython", 245 | "version": 3 246 | }, 247 | "file_extension": ".py", 248 | "mimetype": "text/x-python", 249 | "name": "python", 250 | "nbconvert_exporter": "python", 251 | "pygments_lexer": "ipython3", 252 | "version": "3.9.12" 253 | } 254 | }, 255 | "nbformat": 4, 256 | "nbformat_minor": 5 257 | } 258 | -------------------------------------------------------------------------------- /webscrapping/scrapper.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "id": "64f1e2a7-3405-4c8d-8edb-3a77a8b545d0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import requests\n", 11 | "from bs4 import BeautifulSoup\n", 12 | "import csv\n", 13 | "\n", 14 | "def scrape_page(soup, quotes):\n", 15 | " # retrieving all the quote
HTML element on the page\n", 16 | " quote_elements = soup.find_all('div', class_='quote')\n", 17 | "\n", 18 | " # iterating over the list of quote elements\n", 19 | " # to extract the data of interest and store it\n", 20 | " # in quotes\n", 21 | " for quote_element in quote_elements:\n", 22 | " # extracting the text of the quote\n", 23 | " text = quote_element.find('span', class_='text').text\n", 24 | " # extracting the author of the quote\n", 25 | " author = quote_element.find('small', class_='author').text\n", 26 | "\n", 27 | " # extracting the tag HTML elements related to the quote\n", 28 | " tag_elements = quote_element.find('div', class_='tags').find_all('a', class_='tag')\n", 29 | "\n", 30 | " # storing the list of tag strings in a list\n", 31 | " tags = []\n", 32 | " for tag_element in tag_elements:\n", 33 | " tags.append(tag_element.text)\n", 34 | "\n", 35 | " # appending a dictionary containing the quote data\n", 36 | " # in a new format in the quote list\n", 37 | " quotes.append(\n", 38 | " {\n", 39 | " 'text': text,\n", 40 | " 'author': author,\n", 41 | " 'tags': ', '.join(tags) # merging the tags into a \"A, B, ..., Z\" string\n", 42 | " }\n", 43 | " )\n", 44 | "\n", 45 | "# the url of the home page of the target website\n", 46 | "base_url = 'https://quotes.toscrape.com'\n", 47 | "\n", 48 | "# defining the User-Agent header to use in the GET request below\n", 49 | "headers = {\n", 50 | " 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'\n", 51 | "}\n", 52 | "\n", 53 | "# retrieving the target web page\n", 54 | "page = requests.get(base_url, headers=headers)\n", 55 | "\n", 56 | "# parsing the target web page with Beautiful Soup\n", 57 | "soup = BeautifulSoup(page.text, 'html.parser')\n", 58 | "\n", 59 | "# initializing the variable that will contain\n", 60 | "# the list of all quote data\n", 61 | "quotes = []\n", 62 | "\n", 63 | "# scraping the home page\n", 64 | "scrape_page(soup, quotes)\n", 65 | "\n", 66 | "# getting the \"Next →\" HTML element\n", 67 | "next_li_element = soup.find('li', class_='next')\n", 68 | "\n", 69 | "# if there is a next page to scrape\n", 70 | "while next_li_element is not None:\n", 71 | " next_page_relative_url = next_li_element.find('a', href=True)['href']\n", 72 | "\n", 73 | " # getting the new page\n", 74 | " page = requests.get(base_url + next_page_relative_url, headers=headers)\n", 75 | "\n", 76 | " # parsing the new page\n", 77 | " soup = BeautifulSoup(page.text, 'html.parser')\n", 78 | "\n", 79 | " # scraping the new page\n", 80 | " scrape_page(soup, quotes)\n", 81 | "\n", 82 | " # looking for the \"Next →\" HTML element in the new page\n", 83 | " next_li_element = soup.find('li', class_='next')\n", 84 | "\n", 85 | "# reading the \"quotes.csv\" file and creating it\n", 86 | "# if not present\n", 87 | "csv_file = open('quotes.csv', 'w', encoding='utf-8', newline='')\n", 88 | "\n", 89 | "# initializing the writer object to insert data\n", 90 | "# in the CSV file\n", 91 | "writer = csv.writer(csv_file)\n", 92 | "\n", 93 | "# writing the header of the CSV file\n", 94 | "writer.writerow(['Text', 'Author', 'Tags'])\n", 95 | "\n", 96 | "# writing each row of the CSV\n", 97 | "for quote in quotes:\n", 98 | " writer.writerow(quote.values())\n", 99 | "\n", 100 | "# terminating the operation and releasing the resources\n", 101 | "csv_file.close()" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": null, 107 | "id": "54c0fc0e-1829-42f0-9eb1-4196971c17fc", 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [] 111 | } 112 | ], 113 | "metadata": { 114 | "kernelspec": { 115 | "display_name": "default:Python", 116 | "language": "python", 117 | "name": "conda-env-default-py" 118 | }, 119 | "language_info": { 120 | "codemirror_mode": { 121 | "name": "ipython", 122 | "version": 3 123 | }, 124 | "file_extension": ".py", 125 | "mimetype": "text/x-python", 126 | "name": "python", 127 | "nbconvert_exporter": "python", 128 | "pygments_lexer": "ipython3", 129 | "version": "3.9.12" 130 | } 131 | }, 132 | "nbformat": 4, 133 | "nbformat_minor": 5 134 | } 135 | --------------------------------------------------------------------------------