I have the following list:

`itemlist=[('ItemA', '0', 'Type1'), ('ItemA', '0', 'Type2'),('ItemA', '0', 'Type1'), ('ItemB', '0', 'Type2'), ('ItemA', '1', 'Type2'), ('ItemB', '2', 'Type1'), ('ItemB', '1', 'Type3'), ('ItemB', '1', 'Type1'), ('ItemC', '1', 'Type4'), ('ItemD', '1', 'Type4')]`

Next, i grouped items by number, and count numbers:

```
from itertools import groupby

sortkeyfn_num = key = lambda s:s[0]
itemlist.sort(key=sortkeyfn_num)

result_name_dict = {}
for key,valuesiter in groupby(itemlist, key=sortkeyfn_num):
    result_name_dict[key] = tuple(v[1] for v in valuesiter)

res = {}
for k in result_name_dict.keys():
for i in result_name_dict.values()[result_name_dict.keys().index(k)]:
    res.setdefault(i, 0)
    res[i] += 1
print k,'=', res
res.clear()

```

Result:

```
ItemB = {'1': 2, '0': 1, '2': 1}
ItemC = {'1': 1}
ItemA = {'1': 1, '0': 3}
ItemD = {'1': 1}

```

But how to group items by number and type, and count types in result?
Result must be, for example:

```
ItemA 0: Type1 = 2
ItemA 0: Type2 = 1
ItemA 1: Type2 = 1
ItemB 0: Type2 = 1
ItemB 1: Type3 = 2

```

Thanks.