1. #reverse string #set up two stack and if it’s reverse put it in to the first stack #if it’s not going to reverse, put it in to another stack and finally combine two stackclass Solution(object): def reverseString(self, message): words = set(“abcdefghijklmnopqrstuvwxyz”) r, ur = [], [] if not message: return message index = 0 last = 0 while index < len(message): if message[index] not in words: tmp = “” while index < len(message) and message[index] not in words: tmp += message[index] index += 1 ur.append(tmp) last = 0 else: tmp = “” while index < len(message) and message[index] in words: tmp += message[index] index += 1 r.append(tmp) last = 1 #now r has all reversed and ur has all unreversed rel = [] if last == 1: rel.append(r.pop()) for i in xrange(len(ur)): rel.append(ur ) if r: rel.append(r.pop()) else: for i in xrange(len(ur)): rel.append(ur ) if r: rel.append(r.pop()) while r: rel.append(r.pop()) return “”.join(rel)print Solution().reverseString(“hello my friend and I want to be with you guys ####, ####, xy”)