← Back to challenges

Destructuring Assignment (Ignoring Values)

PythonMediumlanguage_fundamentalsloopslogic

Instructions

You can assign variables from lists like this:

first, _ , last = [1, 2, 8]

first   = lst[0]

_   = ignores second value (2)

last   = lst[-1]

print(first) ➞ outputs 1
print(last) ➞ outputs 8

Notes

  • Your solution should be just One Line of code.

  • Another version of this challenge.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: AND, OR and NOT