[New Concept Docs]: Unpacking & Multiple Assignment in Python
This issue describes how to implement the unpacking and multiple assignment concept docs.
You can find the related concept exercise issue here
If you have not yet contributed to concept documents, this issue will require some upfront reading to give you the needed background knowledge.
â Getting started
Please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time.
General Contributing Docs:
- Contributing to Exercism | Exercism and GitHub | - Contributor Pull Request Guide
- What are those Weird Task Tags about?
- Exercism Formatting and Style Guide
- Exercism Markdown Specification
- Reputation
Documents on Language Tracks and Concepts:
đ¯ Goal
These concept docs are meant to teach an understanding/use of unpacking and the * (splat) and ** (double splat) operators in Python.
đĄ Learning objectives
- Understand/use
unpackingthrough the use of*and**prefix operators in various scenarios-
*and**as prefixes ..... not to be confused with*(multiply) and**(exponentiation) as infix, or mathematical operators - what happens in the process of "unpacking" - form, ordering, & iteration
- use in arguments to
functions - use in argument capture for
functions(aka passing an arbitrary number of arguments -- *args * & **kwargs) - use in defining
keyword only arguments - use in iterable (mainly
tupleandlist) unpacking & packing - use in
dictunpacking & packing
-
- Understand/use
unpackingviamultiple assignment- using
multiple assignmentin place ofindexing - using
multiple assigment+*in place ofslicing - using "list-like" syntax & "tuple-like" syntax
- unpacking plus "leftovers" via
*
- using
- Differences between straight
multiple assignmentand*&** - Deep unpacking
đĢ Out of scope
Concepts & Subjects that are Out of Scope (click to open)
-
classes -
comprehensions -
comprehensionsinlambdas -
map(),filter()orfunctools.reduce()in acomprehension -
function-argumentsbeyond explaining briefly how*,**work in function arguments, and how*works in requiring arguments. -
functoolsbeyondfunctools.reduce()(this will get its own exercise) -
generators - using an
assignment expressionor "walrus" operator (:=) alone or in alambda
đ¤ Concepts
Concepts & Related Concepts Covered (click to open)
-
unpacking -
unpacking generalizations -
multiple assignment
âŠī¸ Prerequisites
These are the concepts/concept exercises the student should be familiar with before taking on/learning this concept.
Prereqs (click to open)
-
basics -
bools -
comparisons -
dicts -
dict-methods -
functions -
function-arguments -
higher-order-functions -
functional tools - Identity methods
isandis not -
iteration -
lists -
list-methods -
numbers -
sequences -
sets -
strings -
string-methods -
tuples
đ Resources to refer to
Resources (click to open)
- Trey Hunner: Asterisks in Python - what they are and how to use them
- Trey Hunner: Multiple assignment and tuple unpacking improve Python code readability
- Dan Bader: Python Nested Unpacking
- PEP 3132: Extended Iterable Unpacking
- PEP 0448: Additional Unpacking Generalizations
- Python Tutorial: Arbitrary Argument Lists & Python Tutorial: Unpacking Argument Lists
- Python Docs: Expression Lists
- Python Docs: Defining Functions
- built-ins: Python Docs
đ Files to Be Created
File Detail for this Exercise (click to collapse)
|
Please see the following for more details on these files: concepts
|
đļ Implementation Notes
- Example code should only use syntax & concepts introduced within these docs or one of the prerequisite concept exercises or documents. Where possible, please use REPL formatting, unless you are demonstrating pseudo code or a long code block. Please do not use syntax not previously covered in prerequisite topics or exercises. Please also follow PEP8 guidelines.
- Our markdown and JSON files are checked against prettier . We recommend setting prettier up locally and running it prior to submitting your PR to avoid any CI errors.
đ Next Steps & Getting Help
-
If you'd like to work on this issue, comment saying "I'd like to work on this"(there is no real need to wait for a response, just go ahead, we'll assign you and put a[claimed]label on the issue). - If you have any questions while implementing, please post the questions as comments in here, or contact one of the maintainers on our Slack channel.