On 30 March 2017 at 10:51, Mark E. Haase <meha...@gmail.com> wrote: > Your example is really repeating two things: > > d = [ [0 for _ in range(5)] for _ in range(10) ] > > But since list() uses * for repetition, you could write it more concisely > as: > > d = [[0] * 5] * 10] > > I'm not picking on your specific example. I am only pointing out that Python > gives you the tools you need to build nice APIs. If repetition is an > important part of something you're working on, then consider using > itertools.repeat, writing your own domain-specific repeat() method, or even > override * like list() does. One of the coolest aspects of Python is how a > relatively small set of abstractions can be combined to create lots of > useful behaviors.
I find it weird that not the author, neither the previous repliers noticed that "a repetition other than a for with dummy variable" was already in plain sight, in the very example given. Of course one is also free to write [ [0 for _ in range(5)] for _ in range(10)] if he wishes so. _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/