To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit d866cfff authored by vermeul's avatar vermeul
Browse files

Update 07-Built-in_Functions.md

parent ef6e6da6
......@@ -50,12 +50,14 @@ ValueError: not enough values to unpack (expected 2, got 1)
How can you assure one always gets enough values and if the lastname does not exist, it will receive a default value (e.g. an empty string)?
<strong>
```
firstname, lastname, *_ = 'Voldemort'.split(' ') + ['']
firstname, lastname, *_ = 'Voldemort'.split(' ') + [''] # lastname is ''
firstname, lastname, *_ = 'Dalai Lama'.split(' ') + [''] # lastname is 'Lama'
```
</strong>
The trick is to ensure that the right side of the assignment always returns at least 2 elements. If more elements are returned, they will be passed to the magic underscore `_` variable. The `*_` means that this magic variable is treated as an array. This page shows more tricks you can do by using this variable: https://www.datacamp.com/community/tutorials/role-underscore-python
The trick is to ensure that the right side of the assignment always returns at least 2 elements. If more elements are returned, they will be passed to the magic underscore `_` variable. The `*_` means that this magic variable is treated as an array. [This page](https://www.datacamp.com/community/tutorials/role-underscore-python) shows more tricks you can do by using this variable.
## Filtering: the `filter` function
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment