gratuitous use lambda and reduce in python

def removeDups(string):
    """Remove duplicate characters from a string"""
    return(reduce(lambda x,y: x if x[-1] == y else x+y, list(string)))

return removeDups("ffoobbaarr")
fobar
Advertisements