Destructuring Assignment (Ignoring Values)

Published by Werdna in

You can assign variables from arrays 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

Using Destructuring Assignment (check the Resources tab), your task is to unpack the array writeyourcodehere into three variables, first, a variable to ignore all middle values and last.

Notes

  • Your solution should be just One Line of code.
  • If your solution is longer than one line of code, please check the Resources tab.
  • Another version of this challenge.
Watch a quick demo on how Edabit works.