import itertools as it

S = 'abc'
S1 = 'abcd'
S2 = 'abcde'
S3 = 'abcdef'
S4 = 'abcdefg'

def countK(f, S):
    subsets = []
    for r in xrange(1, len(S) + 1):
        subsets.extend([s for s in f(S, r)])
    return subsets

print 'number of k permutations for all k with different string lengths'
for s in (S, S1, S2, S3, S4):
    print len(s), 'letters:', len(countK(it.permutations, s))

print 'number of k combinations for all k with different string lengths'
for s in (S, S1, S2, S3, S4):
    print len(s), 'letters:', len(countK(it.combinations, s))
