4 ms·
I don't think the point about splat unpacking really is a correction. Unpacking always requires that the iterable has enough values to assign to the specified v
by nemetroid 3y ago
I don't think the point about splat unpacking really is a correction. Unpacking always requires that the iterable has enough values to assign to the specified variables, this has nothing to do with the use of *middle.
- BoppreH 3y agoTo 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.