[Tutor] Newbie: Help on comparing files

Isr Gish isrgish at fusemail.com
Wed Jan 14 15:01:28 EST 2004


Danny Yoo wrote:

   >However, there's still a module in the Standard Library that should be
   >very appropriate to Isr's question: the 'sets' module:
   >
   >    http://www.python.org/doc/lib/module-sets.html
   >
   >
   >###
   >>>> from sets import Set
   >>>> t1 = 'a b c d'
   >>>> t2 = 'c b d e'
   >>>> s1 = Set(t1.split())
   >>>> s2 = Set(t2.split())
   >>>> s1
   >Set(['a', 'c', 'b', 'd'])
   >>>> s2
   >Set(['c', 'b', 'e', 'd'])
   >>>> s1 - s2
   >Set(['a'])
   >>>> s2 - s1
   >Set(['e'])
   >###
   >
I tried it and it works great. But its not good for what I want. Because I want the return should be in the same order its in the file.
IOW if the first element of file1 is not in file2, then I want it to be the first thing in the output file. And sets don't keep it in the same order that they where before.

Thanks Again
Isr




More information about the Tutor mailing list