Monday, October 3, 2011

difflib

Found another standard library gem: difflib, which allows you to do intelligent string comparisons.

For example:

will find the longest palindrome in a string, e.g.
>>> from palindrome import *
>>> longest_palindrome('asdfracecarasdf')
'racecar'
>>> longest_palindrome('asdffasdfaipreferpiasdfasdfa')
'aipreferpia'

No comments:

Post a Comment