Wednesday, July 6, 2011

Python - All Set for Comparison

I spent entire evening looking for a way to sort the characters in a string and figured it out.
  1. Turn the String into List. 
  2. Sort it. 
  3. Join it back as a String.
And then, I stumbled upon a better way to do string comparison. Convert them to sets!!!
set(stringA).difference(stringB)

Note that it may not be same as
set(stringB).difference(stringA)

Details on set theory here:

Discussion here:


No comments:

Post a Comment