|
|
|
|
|
by BoppreH
1057 days ago
|
|
To be clear, this is only a problem if your array can ever have less than two values, or if you require that `first` and `last` be different values. The mistake is suggesting the unpacking without caveats, because it'll fail in situations that the naive solution doesn't: items = [1]
first = items[0]
middle = items[1:-1]
last = items[-1]
This will still work as long as you have any elements. |
|