List match

Richard Brodie R.Brodie at rl.ac.uk
Thu Aug 17 10:56:29 EDT 2006


"OriginalBrownster" <originalbrownster at gmail.com> wrote in message 
news:1155823451.766317.7640 at 74g2000cwt.googlegroups.com...

> I know this probably is a very easy thing to do in python, but i wanted
> to compare 2 lists and generate a new list that does not copy similar
> entries. An example below
>
> list= ["apple", "banana", "grape"]
> list2=["orange","banana", "pear"]

Other people have already posted solutions but I'll add a couple of
comments:

1. Avoid calling lists 'list', you will break the list built-in function.

2. You don't specify whether the lists are ordered. If there is no
significance to the order of the items, it may be more appropriate
to use sets throughout. Then the answer is just: set3 = set1 | set2. 





More information about the Python-list mailing list