How to generate k+1 length strings from a list of k length strings?
Boris Borcic
bborcic at gmail.com
Fri Jun 9 07:01:00 EDT 2006
> Hum, since your code is not syntactically correct, anything will run
> faster :)
in fact it parses, I was fooled by this line
>> if k in range(1,len(prunedK),1) & i+k <= len(prunedK) -1:
I was fooled because the form "k in range(" tends to imply a for statement ;
in the case of an if statement, one usually uses chained comparisons instead.
If you know i>=0 and i,k are integers (as is implied by context), you could
simply write something like:
if 0 < k < i+k < len(prunedK) :
in the contrary case,
assuming your line does what you want, you should really write it as
if 1 <= k < len(prunedK) and i+k <= len(prunedK)-1 :
or more concisely
if 1 <= k < len(prunedK) >= i+k+1 :
or even
if i+k < len(prunedK) > k > 0 :
More information about the Python-list
mailing list