[Tutor] A Python idiom that I don't get
Kent Johnson
kent37 at tds.net
Wed Apr 26 13:10:40 CEST 2006
w chun wrote:
>>> prefix = os.path.commonprefix(filter( bool, lines ))
>
> that is an interesting and yes, not very optimal way of saving the set
> of non-blank lines. the commonprefix() function takes a list of
> pathnames and returns the longest prefix that all strings have in
> common, presumably for disk filenames, although this sounds like just
> a string processing function that would work with non-pathnames too.
I think it is the commonprefix() call that is expensive, not the filter.
>
>
>>> and I don't understand what that 'bool' is doing. Or rather, I think
>>> that I see what it is doing, but I am not sure - and I don't much like it.
>> :
>>> I tried replacing 'bool'...
>
> it sounds like you did not develop the original code. it seems to
> work... why are you trying to replace it? are you refactoring?
He is porting to Jython which doesn't have bool(), which was introduced
in CPython 2.2.
Kent
More information about the Tutor
mailing list