Hacker. Researching in Quantum Machine Learning in academia and in industry. Privacy enthusiast, expertise in cybersecurity. Musician.
January 16, 2016
Many algorithms require splitting a sequence in a "first, rest" pair. With the new syntax, first, rest = seq, seq[1:] is replaced by the cleaner and probably more efficient: first, *rest = seq I run sum tests where I compared classical list slicing and the new * operator for unpacking. I found out the exact opposite: list slicing not only is better, but it runs in $O(1)$ in certain cases. The first test was against the iterable returned by range(a,b), while the second was against the list on the same range(a,b).
first, rest = seq, seq[1:]
first, *rest = seq
The postings on this site are my own and don't necessarily represent my
employer’s positions, strategies or opinions.
© Alessandro ``Scinawa'' Luongo, 2017 — built with Jekyll using Lagom theme