Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python question

Name: Anonymous 2011-12-20 5:33

How can I remove all the words in one list from another list without loosing duplicates or order?

eg:

aList = ['so', 'what', 'man', 'what']

noiseWords = ['so', 'um', 'crap']

I want aList without the 'so' in noiseWords.
Using Python 3.1 btw, thanks for any help.

Name: Anonymous 2011-12-20 5:52

the easiest way would probably be to convert the noiseWords to a hash set of words, so that look ups can be done in constant time. Then you can step through aList, checking to see if each string in aList appears in noiseWords via a hash table look up. This will maintain the ordering in aList, and duplicate strings in aList that do not appear in noiseWords will still remain.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List