"Ian Kelly" <[EMAIL PROTECTED]> writes:

> On Tue, May 20, 2008 at 11:19 AM, John Salerno <[EMAIL PROTECTED]> wrote:
>> "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>> After being corrected about missing the construction of a None-containing
>>> list, one needs of course to think about the waste of resources, as a
>>> possible result-list is created in any case.
>>
>> Yeah, I was already aware of the list of Nones, which is why I asked. Simply
>> typing the list comprehension without an assignment just *looked* wrong,
>> too.
>
> It sounds like the wasteful list creation is the biggest objection to
> using a list comprehension.  I'm curious what people think of this
> alternative, which avoids populating the list by using a generator
> expression instead (apart from the fact that this is still quadratic,
> which I'm aware of).
>
> def compress(s):
>    new = []
>    filter(None, (new.append(c) for c in s if c not in new))
>    return ''.join(new)

This is crazy!

-- 
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to