468,293 Members | 1,841 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,293 developers. It's quick & easy.

Re: Misuse of list comprehensions?

On Tue, May 27, 2008 at 7:09 PM, Delaney, Timothy (Tim)
<td******@avaya.comwrote:
Ian Kelly wrote:
>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)

Are you aware that filter() returns a list populated from its arguments?
Yes. In this case, it returns an empty list.
Jun 27 '08 #1
0 589

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Elaine Jackson | last post: by
24 posts views Thread by Mahesh Padmanabhan | last post: by
9 posts views Thread by Neuruss | last post: by
42 posts views Thread by Alan McIntyre | last post: by
30 posts views Thread by Steven Bethard | last post: by
6 posts views Thread by Lonnie Princehouse | last post: by
31 posts views Thread by John Salerno | last post: by
reply views Thread by Delaney, Timothy (Tim) | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.