Lie Ryan wrote: > On 12/4/2009 8:28 AM, Ulrich Eckhardt wrote: >> I'm trying to write some code to diff two fonts. What I have is every >> character (glyph) of the two fonts in a list. I know that the list is >> sorted >> by the codepoints of the characters. What I'd like to ask is whether >> there >> is a more elegant solution to the loop below or whether there are any >> rough >> corners in my code (see below). Note that I'm targeting Python 2, not >> 3 yet. >> > > Use sets: > > glyph_1 = set(font1.glyphs) > glyph_2 = set(font2.glyphs) > only_in_1 = glyph_1 - glyph_2 > only_in_2 = glyph_2 - glyph_1 > in_both = glyph_1 & glyph_2 > > that is assuming font1.glyphs's value are hashable.
Ooh that's lovely! I wonder why I've never stumbled across sets in python before? These are SO going to be my favourite new things for the next few weeks. :D Roger. -- http://mail.python.org/mailman/listinfo/python-list