
March 31, 2017
8:23 a.m.
On Thu, Mar 30, 2017 at 10:18 AM, Markus Meskanen <markusmeskanen@gmail.com> wrote:
And wondered, why don't we have a way to repeat other than looping over range() and using a dummy variable?
If it's the assignment to a dummy variable that bothers you, the language already has a way around this: Python 3.6.0 (default, Jan 9 2017, 12:18:47) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information.
import functools, itertools times = functools.partial(itertools.repeat, ()) ["spam" for () in times(4)] ['spam', 'spam', 'spam', 'spam']
Look Ma, no dummy variables! -- Mark