for i inrange(len(strs)): for j inrange(i+1, len(strs)): is_angram = isAnagramCounter(strs[i], strs[j]) if is_angram: if strs[i] in angram_dict: angram_dict[strs[i]].append(strs[j]) elif strs[i] in angram_dict.values(): continue else: angram_dict[strs[i]] = [] angram_dict[strs[i]].append(strs[j])