Partition list with predicate

castironpi at gmail.com castironpi at gmail.com
Wed Apr 23 16:55:20 EDT 2008


On Apr 23, 2:26 pm, Steve Holden <st... at holdenweb.com> wrote:
> Terry Reedy wrote:
> > "Jared Grubb" <jared.gr... at gmail.com> wrote in message
> >news:925822270804230959v557ec5f5re02737709f94d3c6 at mail.gmail.com...
> > | I want a function that removes values from a list if a predicate
> > evaluates
> > | to True.
>
> > Forget the rigamarole you posted, which has several defects.
> > If you must modify the list in place, because you have multiple references
> > to it:
>
> > lst[:] = filter(lambda x: not pred(x), lst)
>
> Wouldn't
>
> lst[:] = [x for x in lst if not pred(x)]
>
> be more direct?
>
> > Otherwise, just lst = filter(....)
>
> And similarly
>
> lst = [x for x in lst if not pred(x)]
>
> regards
>   Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/

And, actually, if you aren't using the GIL, immutables historically
come with locks, which carries concerns with reality (spatialty
+localty), i.e. money, if your technique gains from computer speed,
but there's a right one for a market nitch.  It could be that
computers are doing all they can for everybody's public's good, so if
so, every alternative will be profitable recreationally only.

No reason you can't write a mutable structure that supports multiple
references and keep it off the hard drive, but without defining
Clear( time0, b ) + Set( time0, b ), you can't beat macrolocks without
micros.

And of course, neither RAM nor magnetics offer stereo (two-dimensional
+) seek mechanisms today.  But we'll be allocating squares of memory
eventually.  All technologies are inevitable.



More information about the Python-list mailing list