Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 21:22:42 2019

@author: doppe
"""
import copy
import math


def isAnagram(dict, str2):
    dictCopy = copy.copy(dict)
    for c2 in str2:
        if (c2 in dictCopy):
            dictCopy[c2] -= 1
            if (dictCopy[c2] < 0):
                return False
        else:
            return False
    return True
 
def makeDict(str1):
    dict = {}
    for c in str1:
        if (c in dict):
            dict[c] += 1
        else:
            dict[c] = 1
    return dict

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}
for i in range(0, len(S)):
    if (i in groupList):
        continue
    dict = makeDict(S[i])
    for j in range(i + 1, len(S)):
        if (j in groupList):
            continue
        if (isAnagram(dict, S[j])):
            groupList.append(j)
            if (i in groupDict):
                groupDict[i] += 1
            else:
                groupDict[i] = 2

for v in groupDict.values():
    ans += (v * (v - 1)) / 2

print(int(ans))

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 23:27:57 2019

@author: doppe
"""

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}

ans = 0
for i in range(0, len(S)):
    a = list(S[i])
    a.sort()
    b = ''.join(a)
    if b in groupDict:
        groupDict[b] += 1
    else :
        groupDict[b] = 1

for v in groupDict.values():
    ans += (v * (v - 1)) / 2
        
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 21:22:42 2019

@author: doppe
"""
import copy
import math


def isAnagram(dict, str2):
    dictCopy = copy.copy(dict)
    for c2 in str2:
        if (c2 in dictCopy):
            dictCopy[c2] -= 1
            if (dictCopy[c2] < 0):
                return False
        else:
            return False
    return True
 
def makeDict(str1):
    dict = {}
    for c in str1:
        if (c in dict):
            dict[c] += 1
        else:
            dict[c] = 1
    return dict

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}
for i in range(0, len(S)):
    if (i in groupList):
        continue
    dict = makeDict(S[i])
    for j in range(i + 1, len(S)):
        if (j in groupList):
            continue
        if (isAnagram(dict, S[j])):
            groupList.append(j)
            if (S[i] in groupDict):
                groupDict[S[i]] += 1
            else:
                groupDict[S[i]] = 2

for v in groupDict.values():
    ans += (v * (v - 1)) / 2

print(int(ans))

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 23:27:57 2019

@author: doppe
"""

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}

ans = 0
for i in range(0, len(S)):
    a = list(S[i])
    a.sort()
    b = ''.join(a)
    if b in groupDict:
        groupDict[b] += 1
    else :
        groupDict[b] = 1

for v in groupDict.values():
    ans += (v * (v - 1)) / 2
        
print(int(ans))