Python O(n)
Intuition\nEach word can be converted into canonical form, which is a sorted\nset of the letters in it. So "baacab" becomes "abc". If we have\nk words which\'s 
# Intuition\nEach word can be converted into canonical form, which is a sorted\nset of the letters in it. So "baacab" becomes "abc". If we have\nk words which\'s canonical form is "abc", the number of pairs of\nsimilar words of this canonical form is `k * (k-1) / 2`.\n\n# Approach\nWe iterate over words and convert them to their canonical form. If\nwe have already seen `w` words of this canonical form, the new word\ncan be paired with each one of these `w` words and we increase\nthe number of similar words by `w`.\n\n# Complexity\n- Time complexity:\n $$O(n)$$ for n words.\n\n- Space complexity:\n $$O(n)$$ for n words.\n\n# Code\n```\nfrom collections import defaultdict\n\nclass Solution(object):\n    def similarPairs(self, words):\n        count = defaultdict(int)\n        ans = 0\n        for w in words:\n            key = \' \'.join(sorted(set(w)))\n            ans += count[key]\n            count[key] += 1\n        return ans\n```\n\nBonus one liner:\n```\nfrom collections import Counter\n\nclass Solution(object):\n    def similarPairs(self, words):\n        return sum([k * (k-1) / 2 for k in Counter([\' \'.join(sorted(set(w))) for w in words]).values()])\n```           \n
['Python']