Tuples and sets · 16 / 16 Exercise Medium

Unpacking with a star

Objective

Extended unpacking first, *middle, last = data gathers all the leftover elements in a list. It is the most readable way to separate the beginning and the end of a sequence.

Instructions

  • The input is a line with at least 2 integers separated by spaces.
  • Unpack with first, *middle, last = nums and show First: ..., Middle: [...] (the list), Last: ... and Sum of the middle: ....
Input
1 2 3 4 5
Output
First: 1
Middle: [2, 3, 4]
Last: 5
Sum of the middle: 9

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise