extract elements of n char from a list

Mark McEahern marklists at mceahern.com
Fri Jul 26 13:39:03 EDT 2002


> well, i think that i could use :
>
> nl = [e for e in l if len(e) ==n]
>
> but is it efficient ? are they more efficient ways ? and when is
> it good pythoner technique to use list comprehensions ?

List comprehensions are just dandy, aren't they?

No doubt you've heard about premature optimization is the root of all evil?
Why are you worried about efficiency?  What size list are you talking about?
What other relevant facts are you not sharing with us?  <wink>

I would recommend you focus more on solving your problem and THEN, if it's
too slow, use a profiler to locate bottlenecks.

// mark





More information about the Python-list mailing list