Efficient List Subtraction

KELLEY SCOTT T Scott.Kelley at Colorado.edu
Fri Apr 23 18:08:52 EDT 1999


Does anyone out there have a simple way to compare two lists (some operator perhaps) and
return
a list of *differences*?  By differences, I mean the following:  If had two
lists  like,

a = [1, 4, 5, 100]
b = [4, 5]

the difference between a and b (a-b) would be [1, 100]. I suppose you could
write a couple of for loops to go through each list and compare them, but I
thought there might be a simple way to do this.

I'm also interested in a simple way to returning a list of what is identical between the
two lists.
In the case of the above lists, a and b, they both contain [4, 5].

If anyone out there has a suggestion (or two) I would very much appreciate it.

Cheers! -Scott

-------------------------------------------------------------------
Scott Kelley                                    Phone: 303-492-1474
Dept. MCD Biology                         Fax:   303-492-7744
Campus Box 347                            E-mail: Scott.Kelley at Colorado.edu
University of Colorado
Boulder, CO 80309-0347





More information about the Python-list mailing list