├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── main.yml ├── .gitignore ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── challenge ├── 10k_racetimes.txt ├── __init__.py ├── age_slowest_race.py ├── age_slowest_race_solution.py ├── arg_checker.py ├── arg_checker_solution.py ├── average_race_time.py ├── average_race_time_solution.py ├── calculator.py ├── calculator_solution.py ├── html2markdown.py ├── html2markdown_solution.py ├── linkedin_checker.py ├── linkedin_checker_solution.py ├── medals.py ├── medals_solution.py ├── olympics.txt ├── pairwise_offset.py ├── pairwise_offset_solution.py ├── specifications.txt └── tests │ ├── __init__.py │ ├── test_age_slowest_race.py │ ├── test_arg_checker.py │ ├── test_average_race_time.py │ ├── test_calculator.py │ ├── test_html2markdown.py │ ├── test_linkedin_checker.py │ ├── test_medals.py │ └── test_pairwise_offset.py └── requirements.txt /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/python-3/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster 4 | ARG VARIANT="3.10" 5 | FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} 6 | 7 | # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 8 | ARG NODE_VERSION="none" 9 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 10 | 11 | # [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. 12 | COPY requirements.txt /tmp/pip-tmp/ 13 | RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ 14 | && rm -rf /tmp/pip-tmp 15 | 16 | # [Optional] Uncomment this section to install additional OS packages. 17 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 18 | # && apt-get -y install --no-install-recommends 19 | 20 | # [Optional] Uncomment this line to install global node packages. 21 | # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 22 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Python 3", 3 | "build": { 4 | "dockerfile": "Dockerfile", 5 | "context": "..", 6 | "args": { 7 | "VARIANT": "3.10", // Set Python version here 8 | "NODE_VERSION": "lts/*" 9 | } 10 | }, 11 | "settings": { 12 | "python.defaultInterpreterPath": "/usr/local/bin/python", 13 | "python.linting.enabled": true, 14 | "python.linting.pylintEnabled": true, 15 | "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", 16 | "python.formatting.blackPath": "/usr/local/py-utils/bin/black", 17 | "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", 18 | "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", 19 | "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", 20 | "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", 21 | "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", 22 | "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", 23 | "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", 24 | "python.linting.pylintArgs": ["--disable=C0111"] 25 | }, 26 | "extensions": [ 27 | "ms-python.python", 28 | "ms-python.vscode-pylance" 29 | ], 30 | "remoteUser": "vscode", 31 | "onCreateCommand": "echo PS1='\"$ \"' >> ~/.bashrc" //Set Terminal Prompt to $ 32 | } 33 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners for these exercise files: 2 | # * (asterisk) deotes "all files and folders" 3 | # Example: * @producer @instructor 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Issue Overview 9 | 10 | 11 | ## Describe your environment 12 | 13 | 14 | ## Steps to Reproduce 15 | 16 | 1. 17 | 2. 18 | 3. 19 | 4. 20 | 21 | ## Expected Behavior 22 | 23 | 24 | ## Current Behavior 25 | 26 | 27 | ## Possible Solution 28 | 29 | 30 | ## Screenshots / Video 31 | 32 | 33 | ## Related Issues 34 | 35 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Copy To Branches 2 | on: 3 | workflow_dispatch: 4 | jobs: 5 | copy-to-branches: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | with: 10 | fetch-depth: 0 11 | - name: Copy To Branches Action 12 | uses: planetoftheweb/copy-to-branches@v1.2 13 | env: 14 | key: main 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.bracketPairColorization.enabled": true, 3 | "editor.cursorBlinking": "solid", 4 | "editor.fontFamily": "ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace", 5 | "editor.fontLigatures": false, 6 | "editor.fontSize": 22, 7 | "editor.formatOnPaste": true, 8 | "editor.formatOnSave": true, 9 | "editor.lineNumbers": "on", 10 | "editor.matchBrackets": "always", 11 | "editor.minimap.enabled": false, 12 | "editor.smoothScrolling": true, 13 | "editor.tabSize": 2, 14 | "editor.useTabStops": true, 15 | "emmet.triggerExpansionOnTab": true, 16 | "explorer.openEditors.visible": 0, 17 | "files.autoSave": "afterDelay", 18 | "screencastMode.onlyKeyboardShortcuts": true, 19 | "terminal.integrated.fontSize": 18, 20 | "workbench.colorTheme": "Visual Studio Dark", 21 | "workbench.fontAliasing": "antialiased", 22 | "workbench.statusBar.visible": true 23 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contribution Agreement 3 | ====================== 4 | 5 | This repository does not accept pull requests (PRs). All pull requests will be closed. 6 | 7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license. 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | LinkedIn Learning Exercise Files License Agreement 2 | ================================================== 3 | 4 | This License Agreement (the "Agreement") is a binding legal agreement 5 | between you (as an individual or entity, as applicable) and LinkedIn 6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning 7 | exercise files in this repository (“Licensed Materials”), you agree to 8 | be bound by the terms of this Agreement. If you do not agree to these 9 | terms, do not download or use the Licensed Materials. 10 | 11 | 1. License. 12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn 13 | members during their LinkedIn Learning subscription a non-exclusive, 14 | non-transferable copyright license, for internal use only, to 1) make a 15 | reasonable number of copies of the Licensed Materials, and 2) make 16 | derivative works of the Licensed Materials for the sole purpose of 17 | practicing skills taught in LinkedIn Learning courses. 18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject 19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members 20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable 21 | copyright license to distribute the Licensed Materials, except the 22 | Licensed Materials may not be included in any product or service (or 23 | otherwise used) to instruct or educate others. 24 | 25 | 2. Restrictions and Intellectual Property. 26 | - a. You may not to use, modify, copy, make derivative works of, publish, 27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the 28 | Licensed Materials, except as expressly set forth above in Section 1. 29 | - b. Linkedin (and its licensors) retains its intellectual property rights 30 | in the Licensed Materials. Except as expressly set forth in Section 1, 31 | LinkedIn grants no licenses. 32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any 33 | alleged infringement or misappropriation of any intellectual property rights 34 | of any third party based on modifications you make to the Licensed Materials, 35 | ii) any claims arising from your use or distribution of all or part of the 36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold 37 | harmless, and indemnify LinkedIn and its affiliates (and our and their 38 | respective employees, shareholders, and directors) from any claim or action 39 | brought by a third party, including all damages, liabilities, costs and 40 | expenses, including reasonable attorneys’ fees, to the extent resulting from, 41 | alleged to have resulted from, or in connection with: (a) your breach of your 42 | obligations herein; or (b) your use or distribution of any Licensed Materials. 43 | 44 | 3. Open source. This code may include open source software, which may be 45 | subject to other license terms as provided in the files. 46 | 47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS” 48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY, 49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY 50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR 51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR 52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS 53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING 54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A 55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT. 56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND 57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE 58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR 59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR 60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT 61 | EXPRESSLY STATED IN THESE TERMS. 62 | 63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT, 64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING 65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER 66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU 67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL: 68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT, 69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT 70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS 71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND 72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR 73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE 74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS. 75 | 76 | 6. Termination. This Agreement automatically terminates upon your breach of 77 | this Agreement or termination of your LinkedIn Learning subscription. On 78 | termination, all licenses granted under this Agreement will terminate 79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this 80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue 81 | the availability of some or all of the Licensed Materials at any time for any 82 | reason. 83 | 84 | 7. Miscellaneous. This Agreement will be governed by and construed in 85 | accordance with the laws of the State of California without regard to conflict 86 | of laws principles. The exclusive forum for any disputes arising out of or 87 | relating to this Agreement shall be an appropriate federal or state court 88 | sitting in the County of Santa Clara, State of California. If LinkedIn does 89 | not act to enforce a breach of this Agreement, that does not mean that 90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does 91 | not create a partnership, agency relationship, or joint venture between the 92 | parties. Neither party has the power or authority to bind the other or to 93 | create any obligation or responsibility on behalf of the other. You may not, 94 | without LinkedIn’s prior written consent, assign or delegate any rights or 95 | obligations under these terms, including in connection with a change of 96 | control. Any purported assignment and delegation shall be ineffective. The 97 | Agreement shall bind and inure to the benefit of the parties, their respective 98 | successors and permitted assigns. If any provision of the Agreement is 99 | unenforceable, that provision will be modified to render it enforceable to the 100 | extent possible to give effect to the parties’ intentions and the remaining 101 | provisions will not be affected. This Agreement is the only agreement between 102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior 103 | agreements relating to the Licensed Materials. 104 | 105 | Last Updated: March 2019 106 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2022 LinkedIn Corporation 2 | All Rights Reserved. 3 | 4 | Licensed under the LinkedIn Learning Exercise File License (the "License"). 5 | See LICENSE in the project root for license information. 6 | 7 | ATTRIBUTIONS: 8 | 9 | pytest 10 | https://github.com/pytest-dev/pytest 11 | Copyright (c) 2004 Holger Krekel and others 12 | License: MIT 13 | https://opensource.org/licenses/MIT 14 | 15 | Please note, this project may automatically load third party code from external 16 | repositories (for example, NPM modules, Composer packages, or other dependencies). 17 | If so, such third party code may be subject to other license terms than as set 18 | forth above. In addition, such third party code may also depend on and load 19 | multiple tiers of dependencies. Please review the applicable licenses of the 20 | additional dependencies. 21 | 22 | 23 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 24 | 25 | "The MIT License (MIT) 26 | 27 | Copyright (c) 2004 Holger Krekel and others 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy of 30 | this software and associated documentation files (the ""Software""), to deal in 31 | the Software without restriction, including without limitation the rights to 32 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 33 | of the Software, and to permit persons to whom the Software is furnished to do 34 | so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in all 37 | copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 45 | SOFTWARE." 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Level Up: Advanced Python 2 | This is the repository for the LinkedIn Learning course Level Up: Advanced Python. The full course is available from [LinkedIn Learning][lil-course-url]. 3 | 4 | ![Level Up: Advanced Python ][lil-thumbnail-url] 5 | 6 | Python has quickly become one of the most popular programming languages in the world. If you’re looking to land a new role or stand out from the rest of the crowd, you need to develop your advanced coding skills. Discover integrated Python coding challenges to test your understanding of advanced Python concepts, following along with instructor Jonathan Fernandes, a results-driven data science consultant. Find out more about what it takes to bridge your knowledge gap to the next level, learning how to write highly advanced, production-level code that’s clean, effective, and dynamic. Upon completing this course, you’ll be prepared to leverage your new coding skills in your current or future role.

This course is integrated with GitHub Codespaces, an instant cloud developer environment that offers all the functionality of your favorite IDE without the need for any local machine setup. With GitHub Codespaces, you can get hands-on practice from any machine, at any time—all while using a tool that you’ll likely encounter in the workplace.

Each installment of the Level Up series offers at least 15 bite-sized opportunities to practice programming at various levels of difficulty, so you can challenge yourself and reinforce what you’ve learned. Check out the [Using GitHub Codespaces with this course][gcs-video-url] video to learn how to get a codespace up and running. 7 | 8 | ### Instructor 9 | 10 | Jonathan Fernandes 11 | 12 | Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/jonathan-fernandes). 13 | 14 | [lil-course-url]: https://www.linkedin.com/learning/level-up-advanced-python 15 | [lil-thumbnail-url]: https://cdn.lynda.com/course/3213390/3213390-1667864247408-16x9.jpg 16 | [gcs-video-url]: https://www.linkedin.com/learning/level-up-advanced-python/using-github-codespaces-with-this-course 17 | -------------------------------------------------------------------------------- /challenge/10k_racetimes.txt: -------------------------------------------------------------------------------- 1 | TIME Athlete Race date Date of birth Location 2 | 31:55.6 Edith Masai (KEN) 02 Aug 2008 04 Apr 1967 Cape Elizabeth ME USA 3 | 32:23 Christelle Daunay (FRA) 30 Aug 2015 05 Dec 1974 Arras FRA 4 | 32:23 Christelle Daunay- 2 22 May 2016 05 Dec 1974 Manchester ENG 5 | 32:25 Priscilla Welch (CO/ENG) 02 Mar 1985 22 Nov 1944 Phoenix AZ USA 6 | 32:28 Veerle Dejaeghere (BEL) 06 Sep 2015 01 Aug 1973 Tilburg NED 7 | 32:29 Deena Kastor (CA/USA) 03 Aug 2013 14 Feb 1973 Cape Elizabeth ME USA 8 | 32:31 Colleen De Reuck (CO/USA) 04 Jul 2004 16 Apr 1964 Atlanta GA USA 9 | 32:31 Gloria Marconi (ITA) 20 May 2008 31 Mar 1968 Prato ITA 10 | 32:32.006 Jennifer Rhines (CA/USA) 13 Oct 2014 01 Jul 1974 Boston MA USA 11 | 32:35 Christelle Daunay- 3 18 Jun 2016 05 Dec 1974 Langueux FRA 12 | 32:36.4 Christine Bardelle (FRA) 09 Nov 2014 16 Aug 1974 Ales FRA 13 | 32:39 Carla Beurskens (NED) 10 Apr 1994 15 Feb 1952 Brunssum NED 14 | 32:40 Priscilla Welch- 2 10 Feb 1985 22 Nov 1944 Hallandale FL USA 15 | 32:41 Priscilla Welch- 3 20 Oct 1985 22 Nov 1944 South Bend IN USA 16 | 32:41 Tatyana Pozdniakova (UKR) 11 Apr 1998 04 Mar 1955 New Orleans LA USA 17 | 32:43 Priscilla Welch- 4 10 Oct 1987 22 Nov 1944 Davenport IA USA 18 | 32:47 Joanne Pavey (ENG) 21 Sep 2014 20 Sep 1973 London ENG 19 | 32:50 Colleen De Reuck- 2 12 Jun 2004 16 Apr 1964 New York NY USA 20 | 32:51.8 Sinead Diver (AUS) 18 Jun 2017 17 Feb 1977 Launceston AUS 21 | 32:52 Fatima Yvelain (FRA) 10 Jan 2010 31 Dec 1969 Nice FRA 22 | 32:53 Colleen De Reuck- 3 20 Aug 2005 16 Apr 1964 Minneapolis MN USA 23 | 32:54 Priscilla Welch- 5 21 Apr 1985 22 Nov 1944 Boston MA USA 24 | 32:55 Stephanie Herbst (GA/USA) 26 Jul 2008 27 Dec 1965 Minneapolis MN USA 25 | 32:56 Joanne Pavey- 2 25 May 2015 20 Sep 1973 London ENG 26 | 32:57 Christelle Daunay- 4 27 Dec 2015 05 Dec 1974 Houilles FRA 27 | 32:57 Joanne Pavey- 3 29 May 2017 20 Sep 1973 London ENG 28 | 32:58 Priscilla Welch- 6 04 Jul 1985 22 Nov 1944 Atlanta GA USA 29 | 33:02 Tatyana Pozdniakova- 2 24 Oct 1998 04 Mar 1955 San Antonio TX USA 30 | 33:02 Gitte Karlshoj (DEN) 01 Sep 2002 14 May 1959 Hamburg GER 31 | 33:04 Marie Soderstrom (SWE) 06 May 2002 21 Oct 1960 Orebro SWE 32 | 33:04 Jennifer Rhines- 2 04 Jul 2014 01 Jul 1974 Atlanta GA USA 33 | 33:06 Gitte Karlshoj- 2 02 Sep 2001 14 May 1959 Hamburg GER 34 | 33:07 Christelle Daunay- 5 04 Jul 2015 05 Dec 1974 Atlanta GA USA 35 | 33:08 Priscilla Welch- 7 01 Feb 1986 22 Nov 1944 Miami FL USA 36 | 33:08 Priscilla Welch- 8 22 Oct 1989 22 Nov 1944 Baltimore MD USA 37 | 33:08 Christelle Daunay- 6 28 May 2017 05 Dec 1974 Manchester ENG 38 | 33:09 Lorraine Moller (CO/NZL) 04 Jul 1996 01 Jun 1955 Atlanta GA USA 39 | 33:10 Lorraine Moller- 2 04 Jul 1995 01 Jun 1955 Atlanta GA USA 40 | 33:11 Emma Stepto (ENG) 16 Nov 2014 04 Apr 1970 Leeds ENG 41 | 33:11 Joanne Pavey- 4 20 Sep 2015 20 Sep 1973 Worcester ENG 42 | 33:11 Joanne Pavey - 5 18 Sep 2016 20 Sep 1973 Richmond ENG 43 | 33:12 Chantal Dallenbach (FRA) 23 Mar 2003 24 Oct 1962 La Courneuve FRA 44 | 33:12 Firiya Sultanova (RUS) 11 May 2003 29 Apr 1961 Washington DC USA 45 | 33:12.4 Lyubov Kremlyova (RUS) 23 Feb 2003 21 Dec 1961 San Juan PUR 46 | 33:13 Colleen De Reuck- 4 04 Jul 2005 16 Apr 1964 Atlanta GA USA 47 | 33:16 Gitte Karlshoj- 3 31 Aug 2003 14 May 1959 Hamburg GER 48 | 33:16 Irina Permitina (RUS) 30 Apr 2011 02 Mar 1968 Zhukovskiy RUS 49 | 33:17 Deena Kastor- 2 14 Jun 2014 14 Feb 1973 New York NY USA 50 | 33:18 Marina Belyayeva (RUS) 06 Jun 1999 26 Oct 1958 Tilburg NED 51 | 33:18 Gloria Marconi- 2 20 Jun 2009 31 Mar 1968 Florence ITA 52 | 33:19 Priscilla Welch- 9 11 Mar 1989 22 Nov 1944 Orlando FL USA 53 | 33:19 Tatyana Pozdniakova- 3 30 Apr 1995 04 Mar 1955 Washington DC USA 54 | 33:19 Chantal Dallenbach- 2 02 Feb 2003 24 Oct 1962 Leucate FRA 55 | 33:20 Carla Beurskens- 2 09 May 1993 15 Feb 1952 Brunssum NED 56 | 33:20 Nadezhda Wijenberg (NED) 17 Apr 2005 02 Apr 1964 Hilversum NED 57 | 33:20 Stephanie Herbst- 2 04 Jul 2010 27 Dec 1965 Atlanta GA USA 58 | 33:21 Priscilla Welch- 10 04 Jul 1986 22 Nov 1944 Atlanta GA USA 59 | 33:21 Helen Clitheroe (ENG) 18 May 2014 02 Jan 1974 Manchester ENG 60 | 33:21 Joanne Pavey- 6 10 May 2015 20 Sep 1973 Manchester ENG 61 | 33:21 Jennifer Rhines- 3 26 Mar 2016 01 Jul 1974 New Orleans LA USA 62 | 33:21 Valeria Straneo (ITA) 31 Dec 2016 05 Apr 1976 Rome ITA 63 | 33:22 Ruth Wysocki (CA/USA) 22 Mar 1997 08 Mar 1957 Mobile AL USA 64 | 33:22 Veerle Dejaeghere- 2 16 Aug 2015 01 Aug 1973 Wierden NED 65 | 33:25 Priscilla Welch- 11 25 Nov 1984 22 Nov 1944 Braintree MA USA 66 | 33:25 Lyudmila Korchagina (ON/CAN) 21 Apr 2013 26 Jul 1971 Vancouver BC CAN 67 | 33:25 Jennifer Rhines- 4 15 Nov 2015 01 Jul 1974 Alexandria VA USA 68 | 33:26 Carla Beurskens- 3 02 Apr 1995 15 Feb 1952 Brunssum NED 69 | 33:27 Fatima Yvelain- 2 14 Feb 2010 31 Dec 1969 Cannes FRA 70 | 33:29 Ramilya Burangulova (RUS) 10 Nov 2001 11 Jul 1961 Jacksonville FL USA 71 | 33:29 Lyubov Kremlyova- 2 23 Mar 2002 21 Dec 1961 Mobile AL USA 72 | 33:29 Nadezhda Wijenberg- 2 28 Mar 2005 02 Apr 1964 Utrecht NED 73 | 33:30 Sylvia Mosqueda (CA/USA) 31 Mar 2007 08 Apr 1966 Charleston SC USA 74 | 33:30 Emma Stepto- 2 17 Nov 2013 04 Apr 1970 Leeds ENG 75 | 33:30 Patrizia Morceli (SUI) 28 Dec 2014 11 Jul 1974 Houilles FRA 76 | 33:30 Jennifer Rhines- 5 10 Oct 2016 01 Jul 1974 Boston MA USA 77 | 33:31 Tatyana Pozdniakova- 4 12 Aug 1995 04 Mar 1955 Red Bank NJ USA 78 | 33:31 Jennifer Rhines- 6 06 Sep 2014 01 Jul 1974 Prague CZE 79 | 33:32 Carla Beurskens- 4 12 Sep 1993 15 Feb 1952 Rotterdam NED 80 | 33:32 Christelle Daunay- 7 31 Dec 2016 05 Dec 1974 Rome ITA 81 | 33:33 Colleen De Reuck- 5 25 Sep 2005 16 Apr 1964 Paso Robles CA USA 82 | 33:34 Ramilya Burangulova- 2 26 May 2003 11 Jul 1961 Huntsville AL USA 83 | 33:35 Lorraine Moller- 3 10 Jun 1995 01 Jun 1955 New York NY USA 84 | 33:35 Michelle Cope (ENG) 06 Sep 2015 31 Jan 1972 Cardiff WAL 85 | 33:35.7 Leah Pells (CAN) 17 Apr 2005 09 Nov 1964 Vancouver BC CAN 86 | 33:36 Lucy Elliott (ENG) 19 Mar 2006 09 Mar 1966 Eastleigh ENG 87 | 33:36 Jacqueline Martin Alvarez (ESP) 19 Mar 2016 14 Apr 1974 Laredo ESP 88 | 33:37 Priscilla Welch- 12 13 Apr 1986 22 Nov 1944 Boston MA USA 89 | 33:37 Priscilla Welch- 13 12 Apr 1987 22 Nov 1944 Boston MA USA 90 | 33:37 Marina Belyayeva- 2 07 Aug 1999 26 Oct 1958 Cape Elizabeth ME USA 91 | 33:37 Judi St Hilaire (MA/USA) 05 Aug 2000 05 Sep 1959 Cape Elizabeth ME USA 92 | 33:37 Valentina Yegorova (RUS) 27 Mar 2004 16 Feb 1964 Mobile AL USA 93 | 33:38 Priscilla Welch- 14 04 Jul 1987 22 Nov 1944 Atlanta GA USA 94 | 33:38 Tatyana Pozdniakova- 5 07 Aug 1999 04 Mar 1955 Cape Elizabeth ME USA 95 | 33:38 Anne vanSchuppen (NED) 07 Apr 2002 11 Oct 1960 Hilversum NED 96 | 33:38 Marianne vanderLinden (NED) 19 Oct 2002 06 Jul 1962 Waddinxveen NED 97 | 33:38 Leah Pells- 2 24 Apr 2005 09 Nov 1964 Victoria BC CAN 98 | 33:38 Anzhelika Averkova (UKR) 27 Mar 2010 13 Mar 1969 Charleston SC USA 99 | 33:38 Carmen Oliveras (FRA) 10 Dec 2011 29 Jun 1971 Saint Germain en Laye FRA 100 | 33:39 Michelle Cope- 2 15 Nov 2015 31 Jan 1972 Leeds ENG 101 | 33:40 Tatyana Pozdniakova- 6 08 Jun 1997 04 Mar 1955 Middletown NY USA 102 | -------------------------------------------------------------------------------- /challenge/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /challenge/age_slowest_race.py: -------------------------------------------------------------------------------- 1 | # Source of data: https://www.arrs.run/ 2 | # This dataset has race times for women 10k runners from the Association of Road Racing Statisticians 3 | # Assume a year has 365.25 days 4 | 5 | def get_data(): 6 | with open('10k_racetimes.txt', 'rt') as file: 7 | content = file.read() 8 | return content 9 | 10 | def get_event_time(line): 11 | """Given a line with Jennifer Rhines' race times from 10k_racetimes.txt, 12 | parse it and return a tuple of (age at event, race time). 13 | Assume a year has 365.25 days""" 14 | pass 15 | 16 | def get_age_slowest_times(): 17 | '''Return a tuple (age, race_time) where: 18 | age: AyBd is in this format where A and B are integers''' 19 | races = get_data() 20 | -------------------------------------------------------------------------------- /challenge/age_slowest_race_solution.py: -------------------------------------------------------------------------------- 1 | # Source of data: https://www.arrs.run/ 2 | # This dataset has race times for women 10k runners from the Association of Road Racing Statisticians 3 | # Assume a year has 365.25 days 4 | 5 | import re 6 | import datetime 7 | 8 | def get_data(): 9 | with open('10k_racetimes.txt', 'rt') as file: 10 | content = file.read() 11 | return content 12 | 13 | def get_event_time(line): 14 | """Given a line with Jennifer Rhines' race times from 10k_racetimes.txt, 15 | parse it and return a tuple of (age at event, race time). 16 | Assume a year has 365.25 days""" 17 | 18 | def get_date(date_): 19 | return datetime.datetime.strptime(date_, '%d %b %Y') 20 | 21 | def get_age(race_dob): 22 | race, dob = race_dob 23 | race, dob = get_date(race), get_date(dob) 24 | return divmod((race - dob).days, 365.25) 25 | 26 | def get_race_times(line): 27 | return re.findall(r'\d{2}:\S+', line)[0] 28 | 29 | time = get_race_times(line) 30 | event_dob = re.findall(r'\d{2} \w{3} \d{4}', line) 31 | age = get_age(event_dob) 32 | return (age, time) 33 | 34 | 35 | def get_age_slowest_times(): 36 | '''Return a tuple (age, race_time) where: 37 | age: AyBd is in this format where A and B are integers''' 38 | races = get_data() 39 | race_age = [] 40 | for line in races.splitlines(): 41 | if 'Jennifer Rhines' in line: 42 | race_age.append(get_event_time(line)) 43 | slowest_race = max(race_age, key=lambda x: x[1]) 44 | slowest_age, slowest_race_time = slowest_race 45 | 46 | def format_date(age): 47 | years, days = age 48 | return f'{int(years)}y{int(days)}d' 49 | 50 | return (format_date(slowest_age), slowest_race_time) -------------------------------------------------------------------------------- /challenge/arg_checker.py: -------------------------------------------------------------------------------- 1 | 2 | def arg_checker(*arg_types): 3 | '''An argument checker decorator that checks both: 4 | - The number of variables that you use for a function 5 | - The type of each variable. 6 | Raises a TypeError if either of these fail''' 7 | pass -------------------------------------------------------------------------------- /challenge/arg_checker_solution.py: -------------------------------------------------------------------------------- 1 | from functools import wraps 2 | 3 | def arg_checker(*arg_types): 4 | '''An argument checker decorator that checks both: 5 | - The number of variables that you use for a function 6 | - The type of each variable. 7 | Raises a TypeError if either of these fail''' 8 | def decorator(func): 9 | @wraps(func) 10 | def wrapper(*args): 11 | if len(args) != len(arg_types): 12 | raise TypeError(f'Function {func.__name__} takes {len(arg_types)} positional arguments but {len(args)} were given') 13 | for arg, arg_type in zip(args, arg_types): 14 | if not isinstance(arg, arg_type): 15 | raise TypeError(f'Function {func.__name__} expected positional arguments of type {arg_type} but got {type(arg)} instead') 16 | return func(*args) 17 | return wrapper 18 | return decorator -------------------------------------------------------------------------------- /challenge/average_race_time.py: -------------------------------------------------------------------------------- 1 | # Source of data: https://www.arrs.run/ 2 | # This dataset has race times for women 10k runners from the Association of Road Racing Statisticians 3 | 4 | import re 5 | import datetime 6 | 7 | def get_data(): 8 | """Return content from the 10k_racetimes.txt file""" 9 | with open('10k_racetimes.txt', 'rt') as file: 10 | content = file.read() 11 | return content 12 | 13 | def get_rhines_times(): 14 | """Return a list of Jennifer Rhines' race times""" 15 | races = get_data() 16 | pass 17 | 18 | def get_average(): 19 | """Return Jennifer Rhines' average race time in the format: 20 | mm:ss:M where : 21 | m corresponds to a minutes digit 22 | s corresponds to a seconds digit 23 | M corresponds to a milliseconds digit (no rounding, just the single digit)""" 24 | racetimes = get_rhines_times() 25 | pass -------------------------------------------------------------------------------- /challenge/average_race_time_solution.py: -------------------------------------------------------------------------------- 1 | # Source of data: https://www.arrs.run/ 2 | # This dataset has race times for women 10k runners from the Association of Road Racing Statisticians 3 | 4 | import re 5 | import datetime 6 | 7 | def get_data(): 8 | """Return content from the 10k_racetimes.txt file""" 9 | with open('10k_racetimes.txt', 'rt') as file: 10 | content = file.read() 11 | return content 12 | 13 | def get_rhines_times(): 14 | """Return a list of Jennifer Rhines' race times""" 15 | races = get_data() 16 | rhines_times = [] 17 | def get_time(line): 18 | return re.findall(r'\d{2}:\S+', line)[0] 19 | 20 | for line in races.splitlines(): 21 | if 'Jennifer Rhines' in line: 22 | rhines_times.append(get_time(line)) 23 | return rhines_times 24 | 25 | def get_average(): 26 | """Return Jennifer Rhines' average race time in the format: 27 | mm:ss:M where : 28 | m corresponds to a minutes digit 29 | s corresponds to a seconds digit 30 | M corresponds to a milliseconds digit (no rounding, just the single digit)""" 31 | racetimes = get_rhines_times() 32 | total = datetime.timedelta() 33 | for racetime in racetimes: 34 | try: 35 | mins, secs, ms = re.split(r'[:.]', racetime) 36 | total += datetime.timedelta(minutes=int(mins), seconds=int(secs), milliseconds=int(ms)) 37 | except ValueError: 38 | mins, secs = re.split(r'[:.]', racetime) 39 | total += datetime.timedelta(minutes=int(mins), seconds=int(secs)) 40 | return f'{total / len(racetimes)}'[2:-5] 41 | -------------------------------------------------------------------------------- /challenge/calculator.py: -------------------------------------------------------------------------------- 1 | class Calculator: 2 | pass -------------------------------------------------------------------------------- /challenge/calculator_solution.py: -------------------------------------------------------------------------------- 1 | class Calculator: 2 | def __init__(self, *exc_types): 3 | self.exc_types = exc_types 4 | def __enter__(self): 5 | return self 6 | def __exit__(self, exc_type, exc_value, exc_traceback): 7 | self.error = exc_value 8 | return isinstance(exc_value, self.exc_types) -------------------------------------------------------------------------------- /challenge/html2markdown.py: -------------------------------------------------------------------------------- 1 | 2 | def html2markdown(html): 3 | '''Take in html text as input and return markdown''' 4 | pass -------------------------------------------------------------------------------- /challenge/html2markdown_solution.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | ITALICS = re.compile(r'(.+?)') 4 | SPACES = re.compile(r'\s+') 5 | PARAGRAPHS = re.compile(r'

(.+?)

') 6 | URLS = re.compile(r'(.+?)') 7 | 8 | def html2markdown(html): 9 | '''Take in html text as input and return markdown''' 10 | markdown = ITALICS.sub(r'*\1*', html) 11 | markdown = SPACES.sub(r' ', markdown) 12 | markdown = PARAGRAPHS.sub(r'\1\n\n', markdown) 13 | markdown = URLS.sub(r'[\2](\1)', markdown) 14 | return markdown.strip() -------------------------------------------------------------------------------- /challenge/linkedin_checker.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | import re 3 | 4 | with open('specifications.txt', 'rt') as file: 5 | specifications = file.read() 6 | 7 | specs = namedtuple('specs', 'range regex') 8 | #specs range builtin module 9 | #specs regex from re.compile 10 | 11 | def get_linkedin_dict(): 12 | '''Convert specifications into a dict where: 13 | keys: feature 14 | values: specs namedtuple''' 15 | pass 16 | 17 | def check_linkedin_feature(feature_text, url_or_login): 18 | '''Raise a ValueError if the url_or_login isn't login or custom_url 19 | If feature_text is valid, return True otherwise return False''' 20 | pass 21 | -------------------------------------------------------------------------------- /challenge/linkedin_checker_solution.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | import re 3 | 4 | with open('specifications.txt', 'rt') as file: 5 | specifications = file.read() 6 | 7 | specs = namedtuple('specs', 'range regex') 8 | #specs range builtin module 9 | #specs regex from re.compile 10 | 11 | def get_linkedin_dict(): 12 | '''Convert specifications into a dict: 13 | keys: feature 14 | values: specs namedtuple''' 15 | data = {} 16 | minimum, maximum = 0, 0 17 | regex = '' 18 | for line in specifications.splitlines(): 19 | if line: 20 | if 'requirements' in line: 21 | minimum, maximum = re.findall(r'\d+', line) 22 | minimum = int(minimum) 23 | maximum = int(maximum) 24 | elif 'permitted characters' in line: 25 | regex = ''.join(line.split()[2:]) 26 | regex = re.compile(rf'^[{regex}]+$') 27 | elif 'login characters' in line: 28 | regex = ''.join(line.split()[2:]) 29 | regex = regex[::-1] 30 | regex = regex.replace('.', '.\\', 1).replace('-', '-\\', 1) 31 | regex = regex[::-1] 32 | regex = re.compile(rf'^[{regex}]+@[{regex}]+.com|net|org$') 33 | else: 34 | feature = line.split()[-1] 35 | data[feature] = specs(range(minimum, maximum + 1), regex) 36 | return data 37 | 38 | def check_linkedin_feature(feature_text, url_or_login): 39 | '''Raise a ValueError if the url_or_login isn't login or custom_url 40 | If feature_text is valid, return True otherwise return False''' 41 | data = get_linkedin_dict() 42 | result = data.get(url_or_login, None) 43 | if result is None: 44 | raise ValueError('Feature needs to be either login or custom_url') 45 | else: 46 | length = len(feature_text) in data[url_or_login].range 47 | regex = bool(data[url_or_login].regex.search(feature_text)) 48 | return length & regex 49 | 50 | -------------------------------------------------------------------------------- /challenge/medals.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | with open('olympics.txt', 'rt', encoding='utf-8') as file: 4 | olympics = file.read() 5 | 6 | medal = namedtuple('medal', ['City', 'Edition', 'Sport', 'Discipline', 'Athlete', 'NOC', 'Gender', 7 | 'Event', 'Event_gender', 'Medal']) 8 | 9 | medals = [] #Complete this - medals is a list of medal namedtuples 10 | 11 | def get_medals(**kwargs): 12 | '''Return a list of medal namedtuples ''' 13 | pass 14 | -------------------------------------------------------------------------------- /challenge/medals_solution.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | with open('olympics.txt', 'rt', encoding='utf-8') as file: 4 | olympics = file.read() 5 | 6 | medal = namedtuple('medal', ['City', 'Edition', 'Sport', 'Discipline', 'Athlete', 'NOC', 'Gender', 7 | 'Event', 'Event_gender', 'Medal']) 8 | 9 | medals = [medal(*line.split(';')) for line in olympics.splitlines()[1:]] 10 | 11 | def get_medals(**kwargs): 12 | '''Return a list of medal namedtuples ''' 13 | return [medal 14 | for medal in medals 15 | if all(getattr(medal, key) == value 16 | for key,value in kwargs.items())] -------------------------------------------------------------------------------- /challenge/pairwise_offset.py: -------------------------------------------------------------------------------- 1 | def pairwise_offset(sequence, fillvalue, offset): 2 | pass 3 | -------------------------------------------------------------------------------- /challenge/pairwise_offset_solution.py: -------------------------------------------------------------------------------- 1 | from itertools import tee, zip_longest, chain 2 | 3 | def pairwise_offset(sequence, fillvalue='*', offset=0): 4 | it1, it2 = tee(sequence, 2) 5 | return zip_longest(it1, chain(fillvalue * offset, it2), fillvalue=fillvalue) 6 | -------------------------------------------------------------------------------- /challenge/specifications.txt: -------------------------------------------------------------------------------- 1 | feature: custom_url 2 | requirements: between 3 and 100 characters 3 | permitted characters: a-z A-Z 0-9 4 | 5 | feature: login 6 | requirements: between 5 and 50 characters 7 | login characters: a-z A-Z 0-9 . _ - 8 | 9 | 10 | -------------------------------------------------------------------------------- /challenge/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/level-up-advanced-python-3213390/b15946a04a04187eaf5d72ff8256d015b3216f8c/challenge/tests/__init__.py -------------------------------------------------------------------------------- /challenge/tests/test_age_slowest_race.py: -------------------------------------------------------------------------------- 1 | from challenge.age_slowest_race import get_data, get_event_time, get_age_slowest_times 2 | 3 | def test_age(): 4 | expected = '40y67d' 5 | result = get_age_slowest_times()[0] 6 | assert expected == result 7 | 8 | def test_slowest_time(): 9 | expected = '33:31' 10 | result = get_age_slowest_times()[1] 11 | assert expected == result -------------------------------------------------------------------------------- /challenge/tests/test_arg_checker.py: -------------------------------------------------------------------------------- 1 | from challenge.arg_checker import arg_checker 2 | import pytest 3 | 4 | @arg_checker(int, int, int) 5 | def adder(a, b, c): 6 | '''Returns the sum of the arguments''' 7 | return a + b + c 8 | 9 | def test_correct_args(): 10 | assert adder(1, 2, 3) == 6 11 | 12 | def test_incorrect_number_of_args(): 13 | with pytest.raises(TypeError): 14 | adder(1, 2) 15 | 16 | with pytest.raises(TypeError): 17 | adder(1, 2, 3, 4) 18 | 19 | def test_type_of_args(): 20 | with pytest.raises(TypeError): 21 | adder('1', 2, 3) 22 | 23 | with pytest.raises(TypeError): 24 | adder(1, 2.0, 3) 25 | 26 | with pytest.raises(TypeError): 27 | adder(1, 2, '3') 28 | 29 | def test_decorated_function(): 30 | assert adder.__name__ == 'adder' 31 | assert adder.__doc__ == 'Returns the sum of the arguments' 32 | -------------------------------------------------------------------------------- /challenge/tests/test_average_race_time.py: -------------------------------------------------------------------------------- 1 | from challenge.average_race_time import get_data, get_average, get_rhines_times 2 | 3 | def test_rhine_times(): 4 | result = get_rhines_times() 5 | expected = ['32:32.006', '33:04', '33:21', '33:25', '33:30', '33:31'] 6 | assert result == expected 7 | 8 | def test_average_race_time(): 9 | result = get_average() 10 | expected = '33:13.8' 11 | assert result == expected 12 | -------------------------------------------------------------------------------- /challenge/tests/test_calculator.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from challenge.calculator import Calculator 3 | 4 | def test_no_error(): 5 | with Calculator(TypeError, ValueError, NameError, ZeroDivisionError) as c: 6 | print(1 * 2) 7 | print(2 / 3) 8 | print(3 + 4) 9 | assert c.error == None 10 | 11 | def test_zero_division_error(): 12 | with pytest.raises(ZeroDivisionError): 13 | with Calculator(TypeError, ValueError, NameError, ZeroDivisionError) as c: 14 | print(1 * 2) 15 | print(2 / 0) 16 | print(3 + 4) 17 | raise c.error 18 | 19 | def test_type_error(): 20 | with pytest.raises(TypeError): 21 | with Calculator(TypeError, ValueError, NameError, ZeroDivisionError) as c: 22 | print(1 * 2) 23 | print(2 + '2') 24 | print(3 + 4) 25 | raise c.error 26 | 27 | def test_value_error(): 28 | with pytest.raises(ValueError): 29 | with Calculator(TypeError, ValueError, NameError, ZeroDivisionError) as c: 30 | print(1 * 2) 31 | print(2 + int('a')) 32 | print(3 + 4) 33 | raise c.error 34 | 35 | def test_name_error(): 36 | with pytest.raises(NameError): 37 | with Calculator(TypeError, ValueError, NameError, ZeroDivisionError) as c: 38 | print(1 * 2) 39 | print(2 / num) 40 | print(3 + 4) 41 | raise c.error -------------------------------------------------------------------------------- /challenge/tests/test_html2markdown.py: -------------------------------------------------------------------------------- 1 | from challenge.html2markdown import html2markdown 2 | 3 | def test_italics(): 4 | html = 'This is in italics. So is this' 5 | expected = 'This is in *italics*. So is *this*' 6 | actual = html2markdown(html) 7 | assert actual == expected 8 | 9 | def test_spaces(): 10 | html = 'This sentence has a lot of \ninteresting white spaces.' 11 | expected = 'This sentence has a lot of interesting white spaces.' 12 | actual = html2markdown(html) 13 | assert actual == expected 14 | 15 | def test_single_paragraph(): 16 | html = '

This is a paragraph.

' 17 | expected = 'This is a paragraph.' 18 | actual = html2markdown(html) 19 | assert actual == expected 20 | 21 | def test_multiple_paragraphs(): 22 | html = '

This is a paragraph.

This is another\nparagraph.

' 23 | expected = 'This is a paragraph.\n\nThis is another paragraph.' 24 | actual = html2markdown(html) 25 | assert actual == expected 26 | 27 | def test_urls(): 28 | html = ( 29 | 'This is the link to the html2markdown package and ' 30 | 'here is another link to the project homepage' 31 | ) 32 | expected = ( 33 | 'This is the [link](https://pypi.org/project/html2markdown/) to the html2markdown package and ' 34 | 'here is [another link](https://github.com/dlon/html2markdown) to the project homepage' 35 | ) 36 | actual = html2markdown(html) 37 | assert actual == expected -------------------------------------------------------------------------------- /challenge/tests/test_linkedin_checker.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from challenge.linkedin_checker import (get_linkedin_dict, 3 | check_linkedin_feature, 4 | specifications, 5 | specs) 6 | 7 | def test_correct_custom_url(): 8 | assert check_linkedin_feature('jonathanafernandes', 'custom_url') 9 | assert check_linkedin_feature('jonfernandes2000', 'custom_url') 10 | assert check_linkedin_feature('JonathanFernandes', 'custom_url') 11 | assert check_linkedin_feature('JonathanFernandes2000', 'custom_url') 12 | # atleast 3 characters 13 | assert check_linkedin_feature('jof', 'custom_url') 14 | # atmost 100 characters 15 | assert check_linkedin_feature('jonathanafernandes20' + '0' * 80, 'custom_url') 16 | 17 | def test_incorrect_custom_url(): 18 | assert check_linkedin_feature('jonathanafernande$', 'custom_url') == False 19 | assert check_linkedin_feature('jon-fernandes2000', 'custom_url') == False 20 | assert check_linkedin_feature('Jonathan_Fernandes', 'custom_url') == False 21 | assert check_linkedin_feature('JonathanFernandes2000!!', 'custom_url') == False 22 | # less than 3 characters 23 | assert check_linkedin_feature('jf', 'custom_url') == False 24 | # valid regex more than 100 characters 25 | assert check_linkedin_feature('jonathanafernandes20' + '0' * 81, 'custom_url') == False 26 | 27 | def test_correct_email(): 28 | assert check_linkedin_feature('jf@gmail.com', 'login') 29 | assert check_linkedin_feature('jonathanfernandes@gmail.com', 'login') 30 | assert check_linkedin_feature('jonathan-fernandes@gmail.com', 'login') 31 | assert check_linkedin_feature('jonathan_fernandes@gmail.com', 'login') 32 | assert check_linkedin_feature('jonathan.fernandes@gmail.com', 'login') 33 | # atmost 50 characters 34 | assert check_linkedin_feature(f'jonathanfernandes{"0" * 23}@gmail.com', 'login') 35 | 36 | def test_incorrect_email(): 37 | assert check_linkedin_feature('jonathangmail.com', 'login') == False 38 | assert check_linkedin_feature('jonathanfernandes@gmail.biz', 'login') == False 39 | assert check_linkedin_feature('jonathanfernandes@gmail.co.uk', 'login') == False 40 | # valid email regex but more than 50 characters 41 | assert check_linkedin_feature(f'jonathanfernandes{"0" * 24}@gmail.com', 'login') == False 42 | 43 | def test_incorrect_feature(): 44 | with pytest.raises(ValueError): 45 | assert check_linkedin_feature('jonathanafernandes', 'www') 46 | assert check_linkedin_feature('jonathanafernandes', 'webpage') 47 | assert check_linkedin_feature('jonathanafernandes', 'social') 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /challenge/tests/test_medals.py: -------------------------------------------------------------------------------- 1 | from challenge.medals import medal, medals, get_medals 2 | 3 | def test_two_medals(): 4 | expected = [medal(City='Los Angeles', Edition='1984', Sport='Athletics', Discipline='Athletics', Athlete='LEWIS, Carl', NOC='USA', Gender='Men', Event='100m', Event_gender='M', Medal='Gold'), 5 | medal(City='Seoul', Edition='1988', Sport='Athletics', Discipline='Athletics', Athlete='LEWIS, Carl', NOC='USA', Gender='Men', Event='100m', Event_gender='M', Medal='Gold')] 6 | actual = get_medals(Athlete='LEWIS, Carl', Event='100m') 7 | assert actual == expected 8 | 9 | def test_pipe_dream(): 10 | expected = [] 11 | actual = get_medals(Athlete='FERNANDES, Jonathan') 12 | assert actual == expected 13 | 14 | def test_one_kwarg(): 15 | expected = 1459 16 | actual = len(get_medals(Edition='1984')) 17 | assert actual == expected -------------------------------------------------------------------------------- /challenge/tests/test_pairwise_offset.py: -------------------------------------------------------------------------------- 1 | from challenge.pairwise_offset import pairwise_offset 2 | 3 | def test_no_offset(): 4 | actual = list(pairwise_offset('abcde')) 5 | expected = [('a', 'a'), ('b', 'b'), ('c', 'c'), ('d', 'd'), ('e', 'e')] 6 | assert expected == actual 7 | 8 | def test_fillvalue(): 9 | actual = list(pairwise_offset('abcd', fillvalue='-', offset=1)) 10 | expected = [('a', '-'), ('b', 'a'), ('c', 'b'), ('d', 'c'), ('-', 'd')] 11 | assert expected == actual 12 | 13 | def test_offset(): 14 | actual = list(pairwise_offset([(1, 2), (3, 4), (5, 6)], offset=2)) 15 | expected = [((1, 2), '*'), ((3, 4), '*'), ((5, 6), (1, 2)), ('*', (3, 4)), ('*', (5, 6))] 16 | assert expected == actual 17 | 18 | def test_more_offset_than_items(): 19 | actual = list(pairwise_offset([(1, 2), (3, 4), (5, 6)], offset=4)) 20 | expected = [((1, 2), '*'), ((3, 4), '*'), ((5, 6), '*'), ('*', '*'), ('*', (1, 2)), ('*', (3, 4)), ('*', (5, 6))] 21 | assert expected == actual 22 | 23 | 24 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pytest 2 | --------------------------------------------------------------------------------