start = 0
end = 10000
a = {4:0,3:0,2:0,1:0}
t = set()
for i in range(start,end):
t.clear()
[t.add(s) for s in '%04d' % i]
if len(t) == 1:
a[4] += 1
elif len(t) == 3:
a[2] += 1
elif len(t) == 4:
a[1] += 1
elif ('%04d' % i).count(t.pop()) != 2:
a[3] += 1
print a
# {1:5040,2:4320,3:360,4:10}