Re: Coding style



PTY wrote:

It looks like there are two crowds, terse and verbose. I thought terse
is perl style and verbose is python style. BTW, lst = [] was not what
I was interested in :-) I was asking whether it was better style to
use len() or not.

It's not canonical Python to use len() in this case. From PEP 8:

- For sequences, (strings, lists, tuples), use the fact that empty
sequences are false.

Yes: if not seq:
if seq:

No: if len(seq)
if not len(seq)

The whole reason that a sequence supports testing is exactly for this
scenario. This is not an afterthought -- it's a fundamental design
decision of the language.

Regards,
Pat

.



Relevant Pages

  • Re: Optimize a sequence function
    ... traversing a big list of sequences I can say: ... sequence of the set and I get just that, using very few memory, very ... I am assuming that seq is always a list. ... for elt in set ...
    (comp.lang.lisp)
  • Re: Optimize a sequence function
    ... In deciding which elts to get don't you ... have to traverse the set to begin with? ... seq with the indexes, why not the elts?) ... traversing a big list of sequences I can say: ...
    (comp.lang.lisp)
  • Re: Addition of sequences
    ... elanamig wrote: ... Both sequences are from i=0 to infinity, and all terms are either 0 or ... are binary sequences a special case? ...
    (sci.math)
  • Re: Python Generators
    ... for seq in sequences: ... yield item ...
    (comp.lang.python)