-
Notifications
You must be signed in to change notification settings - Fork 122
Python Snippets
Stefan Petrovic edited this page Mar 10, 2019
·
2 revisions
Use this snippet template to write a new snippet.
-
Snippet filenames must correspond to the title of the snippet and to the function name. For example, if your snippet is titled
### awesome_snippet
the filename should beawesome_snippet.md
and the function name should beawesome_snippet
.- Use
snake_case
, notkebab-case
orcamelCase
. - Avoid capitalization of words.
- Please follow the (PEP8)[https://www.python.org/dev/peps/pep-0008/] guidelines.
- Use
-
Snippet titles should have be the same as the name of the function that is present in the snippet.
- All snippet titles must be prefixed with
###
and be at the very first line of your snippet. - Snippet titles must be unique (although if you cannot find a better title, just add some placeholder at the end of the filename and title and we will figure it out).
- Follow snippet titles with an empty line.
- All snippet titles must be prefixed with
-
Snippet descriptions must be short and to the point. Try to explain what the snippet does and how the snippet works and what inbuilt features/modules are used. Remember to include what functions you are using and why.
- Follow snippet descriptions with an empty line.
-
Snippets CAN NOT use any external modules. Only the modules and function inbuilt in
python 3.6
shall be used. -
Snippet code must be enclosed inside
```python
and```
.- Remember to start your snippet's code on a new line below the opening backticks.
- Try to keep your snippets' code short and to the point. Use modern techniques and features. Make sure to test your code before submitting.
- All snippets must be followed by one (more if necessary) test case after the code, in a new block enclosed inside
```python
and```
. The syntax for this ismy_function('test_input') # 'test_output'
. Use multiline examples only if necessary. - Try to make your function name unique, so that it does not conflict with existing snippets.
- Snippet functions do not have to handle errors in input, unless it's necessary (e.g. a mathematical function that cannot be extended to negative numbers should handle negative input appropriately).
- Snippets should be short (usually below 20 - 30 lines). If your snippet is longer than that, you can still submit it, and we can help you shorten it or figure out ways to improve it.
- Snippets should solve real-world problems, no matter how simple.
- Snippets should be abstract enough to be applied to different scenarios.
- It is not mandatory but highly appreciated if you provide test cases and/or performance tests.