{"id":16551531,"url":"https://github.com/kimfucious/pythonic_algocasts","last_synced_at":"2025-04-04T21:23:56.934Z","repository":{"id":121841456,"uuid":"145259732","full_name":"kimfucious/pythonic_algocasts","owner":"kimfucious","description":"🐍 A pythonic version of exercises based on Stephen Grider's The Coding Interview Bootcamp: Algorithms + Datastructures","archived":false,"fork":false,"pushed_at":"2023-07-17T18:33:01.000Z","size":75,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T06:11:48.847Z","etag":null,"topics":["algocasts","algorithm-challenges","bootcamp","data-structures","htmltestrunner","livereload","python","stephengrider"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kimfucious.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-18T23:40:54.000Z","updated_at":"2020-04-25T12:40:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"9038fabd-8329-499a-a7f0-6b47a1b320e2","html_url":"https://github.com/kimfucious/pythonic_algocasts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimfucious%2Fpythonic_algocasts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimfucious%2Fpythonic_algocasts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimfucious%2Fpythonic_algocasts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimfucious%2Fpythonic_algocasts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimfucious","download_url":"https://codeload.github.com/kimfucious/pythonic_algocasts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247250323,"owners_count":20908340,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algocasts","algorithm-challenges","bootcamp","data-structures","htmltestrunner","livereload","python","stephengrider"],"created_at":"2024-10-11T19:37:39.727Z","updated_at":"2025-04-04T21:23:56.908Z","avatar_url":"https://github.com/kimfucious.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pythonified Coding Interview Bootcamp Exercises\n\nThis repo contains Pythonic versions of exercises based on **Stephen Grider's** [_The Coding Interview Bootcamp: Algorithms + Datastructures_](https://www.udemy.com/coding-interview-bootcamp-algorithms-and-data-structure/?couponCode=4MORE1234) found on Udemy.  The JavaScript repo is [here](https://github.com/StephenGrider/AlgoCasts).\n\nI created this, as I wanted to apply what I learned in JavaScript from Stephen's course, toward learning Python.\n\nThis repo is not intended to be a rip off of Stephen's work or a replacement for his very informative course targeted at JavaScript. Consider it more of a Pythonic ode.  \n\n\u003e :information_desk_person: I pinged him about doing this, but didn't get a response.  \n\nThis repo is also not a substitute for the ton of material he covers, erudite teaching he provides, and the practical experience he shares throughout the course lectures. In fact, you're not likely to get a whole lot out of these exercises without having access to the course material.  So if you really want a good start toward learning these the concepts behind these exercises (in JavaScript) and then apply them in Python, go buy his course and enjoy what I've created here! :rainbow: :unicorn: :rainbow: :cat: :rainbow: :sheep: :rainbow:\n\n## Features\n\n- Oodles of exercises to practice challenging coding questions\n- Extensive unit tests to verify your solutions\n- Example solutions (often more than one) for every exercise\n\n## Requirements\n\n- [Python 3](https://www.python.org/downloads/):  some tests won't work if you use Python 2\n- A testing framework ( e.g. pytest or unnitest )\n- A text editor:  Atom, Sublime Text, Vim, Visual Studio Code, etc.\n- A terminal\n\n\u003e :floppy_disk:  If you're running Windows 10 try [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10).\n\n\u003e :snake:  There is an excellent Python extension for Visual Studio Code. Check it out [here](https://marketplace.visualstudio.com/items?itemName=ms-python.python).\n\n## Installation\n\n### Clone this repo\n\n1. Go to a place on your machine where you want to download this repo (e.g. `cd ~/workspace/`):\n2. Run one of the following commands:\n\n#### SSH\n\n```shell\ngit clone git@github.com:kimfucious/pythonic_algocasts.git\n```\n\n#### HTTPS \n\n```shell\ngit clone https://github.com/kimfucious/pythonic_algocasts.git \n```\n\nThis repo has both a `requirements.txt` file and a `Pipfile` for making installing dependencies easy.\n\nYou don't need to install any dependencies, if you're planning on just using `unittest` to test your solutions.  \n\nIf you want to use pytest, you can install it manually (see [below](###Test-Frameworks)); otherwise it will be installed by `pip` or `pipenv` along with the following packages:\n\n- A beta version of HTMLTestRunner (creates HTML reports)\n- liveReload (small dev server to display HTML reports)\n- pylint (a Python code linter)\n- other sub-dependencies\n\n### Installing dependencies using pip\n\nI'm using pip3 throughout this documentation, but pip should also work fine.\n\nYou probably already have pip, but here's [some info](https://pip.pypa.io/en/stable/installing/) on installation and upgrading.\n\nYou probably also want to create an new Python environment.  To do that, navigate to this downloaded repo's root directory, and run the following:\n\n```shell\npython3 -m venv env\nsource env/bin/activate\n```\n\n\u003e :point_up:  The above commands assume you are using bash or zsh.  Refer to the below or see [here](https://docs.python.org/3/library/venv.html) for using `venv` in other shells.\n\n| Platform | Shell      | Command to activate virtual environment |\n| -------- | ---------- | --------------------------------------- |\n| Posix    | bash/zsh   | $ source /bin/activate                  |\n|          | fish       | $ . /bin/activate.fish                  |\n|          | csh/tcsh   | $ source /bin/activate.csh              |\n| Windows  | cmd.exe    | C:\\\u003e \\Scripts\\activate.bat              |\n|          | PowerShell | PS C:\\\u003e \\Scripts\\Activate.ps1           |\n\nRun `pip3 list`, and you should see only two files:\n\n```shell\nPackage    Version\n---------- -------\npip        10.0.1 \nsetuptools 39.0.1 \n```\n\nYou'll get prompted to upgrade pip at this point.  Go ahead and do that, if you want.\n\nNext, run:\n\n```shell\npip3 install -r requirements.txt\n```\n\nOnce this completes, run `pip3 list` again, and Bob's your uncle.\n\n### Installing using Pipenv\n\nPipenv is awesome.  You can learn about it [here](https://docs.pipenv.org).\n\nAfter installing Pipenv, navigate to this project's root and run the following:\n\n```shell\npipenv install\npipenv shell\n```\n\n## Contents\n\n\u003e :point_up:  Do not remove any of the `__init__.py` files from within the repo, or it will break test discovery.\n\n### Exercises\n\nStarter files for each exercise with instructions that describe what the solution should be.\n\nWhile you can, for the most part, approach these exercises in any order. The course does tend to build upon itself, so you may want to follow the order in which the lectures are covered in Stephen's course.\n\n#### Order of exercises\n\n1. String Reversal (reversestring)\n2. Palindromes\n3. Integer Reversal (reverseint)\n4. MaxChars\n5. FizzBuzz\n6. List Chunking (chunk)\n7. Anagrams\n8. Sentance Capitalization (capitalize)\n9. Printing Steps (steps)\n10. Two Sided Steps (pyramid)\n11. Vowels\n12. Matrix Spiral (matrix)\n13. Fibonacci (fib and fib_memoized)\n14. Queue\n15. Weave\n16. Stack\n17. Queue From Stack (qfroms)\n18. Linked Lists (linkedlist)\n19. Midpoint\n20. Circular\n21. From Last (from last)\n22. Tree\n23. Level Width (levelwidth)\n24. Binary Search Tree (bst)\n25. Validating Binary Search Trees (validate)\n26. Events\n27. Bubble Sort, Selection Sort, and Merge Sort (sorting)\n\n### Helpers\n\nSome of the exercies rely on pre-built components (probably not the right word), like: classes, linked lists, queues, and stacks. You'll build such things as you work through the excercises; however, these helpers are in place for exercises with a different, specific focus.\n\n### Misc\n\nThere are two html files in here:\n\n1.  The `events_example.html` file is for the events exercise. Frankly, you won't get much out of this unless you have access to Stephen's course.\n2.  The `linkedlist_directions.html` file is a set of instructions for the fairly long linked list exercise.\n\n### Reports\n\nThis is where HTML test reports will be generated.\n\nI've setup an HTML report generator that will allow you to display the test results in a web browser.\n\nYou can get this going by running the following command from the root of this project.\n\n```shell\npython3 reports.py\n```\n\nTo view the reports, open http://localhost:8080 in your browser, after running the above command.\n\nThere are a few things happening to make this work.\n\n1.  I've setup a test suite containing all of the tests in the `run_all_tests.py` file.\n2.  This file also uses James Sloan's beta version of [HTMLTestRunner](https://github.com/JamesMTSloan/HtmlTestRunner).  I'm using the beta, because James has made it possible to combine multiple test cases into one report.  If/when this [pull request](https://github.com/oldani/HtmlTestRunner/pull/32) comes through, I'll update this project to use the updated release.\n3.  The `reports.py` file launches [livereload](https://livereload.readthedocs.io/en/latest/), which is a dev server that serves up the `test_results.html` file.\n4.  livereload is setup to watch all `*.py` files in the exercises directory.  Any changes to these files, kicks off the `run_all_tests.py` process, which overwrites any existing `test_results.html` file in the reports directory, it then waits a few seconds, and automatically reloads the browser window.\n\n\u003e :point_up:  If you're running into an issue where the browser refreshes before the tests complete, like if you're running fib(39), you can adjust the delay in the `reports.py` file on the line shown below:\n\n```python\nserver.watch(\"./exercises/*.py\",\n             shell(\"python3 run_all_tests.py --quiet\"), delay=3)\n```\n\nThis process is not perfect.  Admittedly, the console output is not pretty.  If you want nice output in the console, checkout `pytest` in [Testing](###Testing-Frameworks).  Also, if there's something really wrong (e.g. SyntaxError) with an exercise solution, the process will crash before any report is generated.  This is usually indicated by something red in the console output, that might resemble this with a bunch of nasty stuff after it, usually ending with the type of error being thrown:\n\n```shell\n[E 180819 00:44:57 server:75] yadda, yadda, yadda SyntaxError: invalid syntax...\n```\n\nWhen this does happen, the report will reload in the browser, but it will be using old data so the results will not be accurate.\n\nAt this point, you can try running your tests manually (see [Testing](##Testing) below) to see more clearly what's going on and fix your solution.\n\nLastly, to generate HTML reports manually without livereload, run the following from the root directory:\n\n```shell\npython3 run_all_tests.py\n```\n\n### Solutions\n\nHere are the examples solutions to the exercises that you can use to compare against your own work or to peek at for inspiration.\n\nFeel free to recommend your solution(s) via a pull request if you come up with anything better, cleaner, clearer, more-pythonic, etc. Please use `doctype` to document your solutions, instead of comments.\n\nExample:\n\n```python\ndef function(x):\n  \"\"\"\n  My super cool solution is based on using kittens, rainbows, and lambdas.\n  You can read about those things at http://kittensrainbowsandlambdas.org\n  \"\"\"\n  pass\n```\n\n\u003e :see_no_evil:  Solutions containing advertisements or other forms of spam/self-promotion won't be considered. This is a learning space, not a marketplace.\n\n### Tests\n\nThere is one test file for each exercise. The naming convention should make it evident as to what tests what.\n\nAll of the test files should be considered done, meaning that you should not need to edit any of them, except for commenting out the `@unittest.skip()` lines when you're ready to test (see [Skipping and Unskipping Tests](###Skipping-and-Unskipping-Tests)). They should _just work_ and are just there to test the solutions that you create for the exercises.\n\n\u003e :beetle:  If you find any mistakes in the tests or have any recomendations to improve them, please raise an issue.\n\nSome of the test files contain one or more test cases (i.e. Classes) and these can contain one to several test methods. See the [Testing](##Testing) section for more info on tests.\n\n## Testing\n\nNote that the `__init__.py` files that you see in the directory structure (and the directory structure itself) are there to enable test discovery. Don't move things around or delete any `__init__.py` files, unless you know that you really want to.\n\n### Testing Frameworks\n\nAt the risk of sounding redundant, all tests have been tested using both `unittest` and `pytest`.\n\nWhile `unittest` is built in to Python, pytest requires installation.\n\nHere's some documentation:\n\n- [pytest installation](https://docs.pytest.org/en/latest/getting-started.html)\n- [Official Python Documentation on unittest](https://docs.python.org/3/library/unittest.html)\n\n### Test Discovery\n\nTo discover all tests, if you're using `unittest`, you can run discovery by doing the following:\n\n1.  Navigate to the root directory of this repo in your terminal\n2.  Run `python3 -m unittest discover`\n\nAs far as I know, `pytest` doesn't have a discovery option, nor is it needed. And, along those lines, `python3 -m unittest` will also discover tests, so take that for what it is.\n\n### Running Tests\n\nTo run all unit tests:\n\n1.  Navigate to the root directory of this repo in your terminal\n2.  Do one of the below:\n\n\u003e :point_up: Remember that we're using Python 3. Don't forget to type `python3` (not python), and don't forget the `-m` bit.\n\n#### pytest\n\n```shell\npython3 -m pytest\n```\n\n#### unittest\n\n```shell\npython3 -m unittest\n```\n\nTo run an individual unit test:\n\n\n1.  Navigate to the root directory of this repo.\n2.  Run either of the below, where `exercise.py` is the name of thing you're trying to test, like `test_anagrams.py`, for example.\n\n\u003e :pushpin:  You can also navigate to the tests directory, and run `python3 -m pytest test_excercise.py`.\n\n#### pytest\n\n`python3 -m pytest tests/test_excercise.py`\n\n#### unittest\n\n`python3 -m unittest tests/test_excercise.py`\n\n\u003e :bulb:  adding --verbose to either of the two above commands will give you a more output in your test results.\n\n### Skipping and Unskipping Tests\n\nYou'll have noticed that all of the tests are skipped when you first try to run them. This is so that you don't see a load of failures and/or errors on exercises that you haven't event attempted to work on yet.\n\nThe following line (i.e. decorator) in a test file will skip an entire test case (multiple methods) or single test cases depending on where it's located.\n\n```python\n@unittest.skip(\"skip the following stuff\")\n```\n\nIn most of the test files, there is one skip decorator located just above the Class defining the test case. In other, more lengthy test files, like Linked List, there might be more cases and, thus, more skip decorators, allowing you to open up the test cases slowly as you progress through the exercises.\n\nTo allow a test case to run, simply comment out the decorator, like this (or delete it if you're feeling bold):\n\n```python\n# @unittest.skip(\"skip the following stuff\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimfucious%2Fpythonic_algocasts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimfucious%2Fpythonic_algocasts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimfucious%2Fpythonic_algocasts/lists"}