4 ms·
I love tuple unpacking but it annoys me endlessly that the *arguments are unpacked into a list, not a tuple. Whereas if you use * in a function signature, you g
by canjobear 4y ago
I love tuple unpacking but it annoys me endlessly that the *arguments are unpacked into a list, not a tuple. Whereas if you use * in a function signature, you get a tuple, not a list. My code always ends up looking like
first, *rest = xs
rest = tuple(rest)
because often I want to hash "rest".
Another trick I often use:
the_only, = xs
This extracts the single element of a one-element iterable and throws an error if xs is empty or has more than one element.