Comparing modified elements in Sets

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Mon Jul 9 19:35:57 EDT 2007


On Mon, 09 Jul 2007 19:57:14 +0000, ChrisEdgemon wrote:

> I've got a set with contents like: [filename1.mp3, filename2.mp3,
> filename3.mp3, ...]
> I've got another set with contents like [filename1.ogg,
> filename3.ogg, ...]
> And another set with contents like [filename1, filename 2, ...]
> 
> I'd like to be able to compare set 1 with set 2 and have it match
> filename1 and filename3, or compare set 1 with 3 and get back
> filename1, filename2.  etc.
> 
> Is there a way for me to do this inside the compare function, rather
> than having to make duplicate copies of each set?

What compare function are you talking about?

Unless you have truly astronomical numbers of unique filenames (and
remember that what's big to you is probably not big to Python), the
easiest way is to make a copy of each set with the file extensions
stripped off the file names. Use os.path.splitext() for that.


-- 
Steven.




More information about the Python-list mailing list