~cpp import sys def Anagram(inFile,outFile): anagrams={} for eachWord in inFile: eachWord=eachWord.strip() key=list(eachWord);key.sort();key=''.join(key) anagrams.setdefault(key,[]).append(eachWord) for eachAnagram in anagrams.itervalues(): print >> outFile, ' '.join(eachAnagram) if __name__=='__main__': Anagram(sys.stdin,sys.stdout)
~cpp import psyco;psyco.bind(Aangram)
을 추가) 3.4초.