In this Kata, you will be given a list of strings and your task will be to find the strings that have the same characters and return the sum of their positions as follows: 

```Haskell
solve(["abc","abbc", "ab", "xyz", "xy", "zzyx"]) = [1,8]
-- we see that the elements at indices 0 and 1 have the same characters, as do those at indices 3 and 5.
-- we therefore return [1,8] because [0+1,3+5] = [1,8]. This result is sorted. 
-- ignore those that don't have at least one matching partner, such as "ab" and "xy".

Another example...
solve(["wkskkkkkk","fokoo","wkskk","uizzzz","fokooff","wkskkkk","uizzzzzzz"]),[5,7,9]);
--The element at index 0 is similar to those at indices 2 and 5; so 0 + 2 + 5 = 7.
--The element at index 1 is similar to that at index 4; so 1 + 4 = 5. 
--The element at index 3 is similar to that at index 6; so 3 + 6 = 9.
--The result must be sorted. We get [5,7,9].
```
More examples in the test cases. 

Good luck!

Source: codewars | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: def solve(arr):
	

Solutions:
from collections import defaultdict

def solve(arr):
	dct = defaultdict(list)
	for (i, fs) in enumerate(map(frozenset, arr)):
		dct[fs].append(i)
	return sorted((sum(lst) for lst in dct.values() if len(lst) > 1))


def solve(lst):
	(seen, result) = (set(), [])
	for (i, st1) in enumerate(lst):
		current = 0
		for (j, st2) in enumerate(lst[i + 1:], i + 1):
			if j not in seen and set(st1) == set(st2):
				current += j
				seen.add(j)
		if current:
			result.append(i + current)
	return sorted(result)


def solve(arr):
	ret = []
	i = len(arr) - 1
	t = None
	while i > -1:
		for j in range(i):
			if arr[j] and set(arr[j]) == set(arr[i]):
				arr[j] = ''
				if not t:
					t = 0
				t += j
		if t != None:
			ret.append(t + i)
			t = None
		i -= 1
	return sorted(ret)


from collections import defaultdict

def solve(arr):
	d = defaultdict(list)
	for (i, x) in enumerate(arr):
		d[frozenset(x)].append(i)
	return sorted((sum(xs) for xs in list(d.values()) if len(xs) > 1))


from itertools import groupby
from operator import itemgetter

def solve(arr):
	s = sorted(((c, sorted(set(a))) for (c, a) in enumerate(arr)), key=itemgetter(1))
	return sorted((sum(map(itemgetter(0), a)) for a in (list(g) for (_, g) in groupby(s, itemgetter(1))) if len(a) > 1))


def solve(arr):
	sums = {}
	for (i, s) in enumerate(arr):
		sums.setdefault(frozenset(s), []).append(i)
	return sorted((sum(indexes) for indexes in sums.values() if len(indexes) > 1))


def solve(a):
	d = {}
	for (i, s) in enumerate(a):
		d.setdefault(frozenset(s), []).append(i)
	return sorted((sum(v) for v in d.values() if len(v) > 1))


from collections import defaultdict

def solve(strings):
	indices_by_chars = defaultdict(list)
	for (i, s) in enumerate(strings):
		indices_by_chars[frozenset(s)].append(i)
	return sorted((sum(js) for js in list(indices_by_chars.values()) if len(js) > 1))


def solve(arr):
	arr = [''.join(sorted(list(set(x)))) for x in arr]
	return sorted((sum((i for (i, y) in enumerate(arr) if x == y)) for x in set(arr) if arr.count(x) >= 2))