Code golf: find all anagrams

后端 未结 8 2138
再見小時候
再見小時候 2021-02-04 06:00

A word is an anagram if the letters in that word can be re-arranged to form a different word.

Task:

  • The shortest source code by character count to find

8条回答
  •  再見小時候
    2021-02-04 06:05

    Python, O(n^2)

    import sys;
    words=sys.stdin.readlines()
    def s(x):return sorted(x.lower());
    print '\n'.join([''.join([a.replace('\n',' ') for a in words if(s(a)==s(w))]) for w in words])
    

提交回复
热议问题