Standard ways to get union, intersection, difference of lists?

Mike C. Fletcher mcfletch at rogers.com
Thu Jun 26 19:27:23 CEST 2003


I've back-ported sets to 2.2.2.  It was a matter of implementing a few 
functions from itertools (which is a Python module IIRC).  Here's the 
majority of the backporting code:

### Backport to 2.2 by Mike Fletcher
from __future__ import generators
def ifilter(predicate, iterable):
    if predicate is None:
        def predicate(x):
            return x
    for x in iterable:
        if predicate(x):
            yield x
def ifilterfalse(predicate, iterable):
    if predicate is None:
        def predicate(x):
            return x
    for x in iterable:
        if not predicate(x):
            yield x
### End backport

There's some more for getting the tests to run under 2.2.2, but that's 
not actually necessary to use the module.

Enjoy,
Mike

John Hunter wrote:

>>>>>>"Steve" == Steve Holden <sholden at holdenweb.com> writes:
>>>>>>            
>>>>>>
>
>    Steve> Not necessarily: I believe you can just pick up the sets
>    Steve> module from CVS and run it under 2.2+.
>
>I just tried import sets from the 2.3b1 distribution under python 2.2,
>but it failed with an ImportError trying to load itertools.  I believe
>itertools is a C module, so perhaps it is not so straightforward to
>use sets from 2.2?
>
>John Hunter
>  
>

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list