repeat items in a list

Rob Gaddi rgaddi at highlandtechnology.invalid
Mon Mar 28 13:30:53 EDT 2016


beliavsky at aol.com wrote:

> On Saturday, March 26, 2016 at 7:24:10 PM UTC-4, Erik wrote:
>> 
>> Or, if you want to "import operator" first, you can use 'operator.add' 
>> instead of the lambda (but you _did_ ask for a one-liner ;)).
>> 
>> Out of interest, why the fascination with one-liners?
>
> Thanks for your reply. Sometimes when I program in Python I think I am not using the full capabilities of the language, so I want to know if there are
> more concise ways of doing things.

Concise is only worth so much.  PEP20 tells us "Explicit is better than
implicit", "Simple is better than complex" and "If the implementation is
hard to explain, it's a bad idea".

Python is a beautifully expressive language.  Your goal should not be to
write the minimum number of lines of code to accomplish the task. 
Your goal should be to write the code such that your grandmother can
understand it.  That way, when you screw it up, you'll be able to easily
figure out where and how you did so.  Or failing that, you can get
grangran to show you.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list