re-implement __eq__ to compare sets with symmetric_difference in python
Question: I have a set of filenames coming from two different directories.

    
    
    currList=set(['pathA/file1', 'pathA/file2', 'pathB/file3', etc.])
    

My code is processing the files, and need to change currList by comparing it
to its content at the former iteration, say processLst. For that, I compute a
symmetric difference:

    
    
    toProcess=set(currList).symmetric_difference(set(processList))
    

Actually, I need the symmetric_difference to operate on the basename
(file1...) not on the complete filename (pathA/file1).

I guess I need to reimplement the `__eq__` operator, but I have no clue how to
do that in python.

  1. is reimplementing `__eq__` the right approach? or
  2. is there another better/equivalent approach?


Answer: Here is a token (and likely poorly constructed) `itertools` version that
should run a little bit faster if speed ever becomes a concern (although agree
that @Zarkonnen's one-liner is pretty sweet, so +1 there :) ).

    
    
    from itertools import ifilter
    
    currList = set(['pathA/file1', 'pathA/file2', 'pathB/file3'])
    processList=set(['pathA/file1', 'pathA/file9', 'pathA/file3'])
    
    # This can also be a lambda inside the map functions - the speed stays the same
    def FileName(f):
      return f.split('/')[-1]
    
    # diff will be a set of filenames with no path that will be checked during
    # the ifilter process
    curr = map(FileName, list(currList))
    process = map(FileName, list(processList))
    diff = set(curr).symmetric_difference(set(process))
    
    # This filters out any elements from the symmetric difference of the two sets
    # where the filename is not in the diff set
    results = set(ifilter(lambda x: x.split('/')[-1] in diff,
                  currList.symmetric_difference(processList)))
    

