unique substring of length k in python:
================================
#!/usr/bin/python
import argparse
p = argparse.ArgumentParser()
p.add_argument('-s')
p.add_argument('-l', type=int)
args = p.parse_args()
entered_str = args.s
entered_len = args.l
print 'Entered string is:', entered_str
print 'Entered length is:', entered_len
#out_raw = list(entered_str)
#print 'The raw char list is:', out_raw
out_raw_k = entered_str[:entered_len]
print 'The shortened raw char list is:', out_raw_k
print 'Unique substring with length of 1:', set(out_raw_k)
print 'Unique substring with length of 1 count:', len(set(out_raw_k))
out = [0, len(set(out_raw_k))]
i = 2
while i <= entered_len:
chunk = (len(out_raw_k)/i)*i
sub_list = [ out_raw_k[y:y+i] for y in range(0, chunk, i) ]
print 'Unique substring with length of', i, ':', set(sub_list)
print 'Unique substring with length of', i, 'count:', len(set(sub_list))
out.append(len(set(sub_list)))
i += 1
print 'Total unique substring count:', sum(out)
=======Output from UNIX============
$ ./test -s phenomenon -l 3
Entered string is: phenomenon
Entered length is: 3
Starting position: 0 substring count: 3 list: ['phe', 'nom', 'eno']
Starting position: 1 substring count: 3 list: ['hen', 'ome', 'non']
Starting position: 2 substring count: 2 list: ['eno', 'men']
Starting position: 3 substring count: 2 list: ['nom', 'eno']
Starting position: 4 substring count: 2 list: ['ome', 'non']
Starting position: 5 substring count: 1 list: ['men']
Starting position: 6 substring count: 1 list: ['eno']
Starting position: 7 substring count: 1 list: ['non']
Total substring list: ['phe', 'nom', 'eno', 'hen', 'ome', 'non', 'eno', 'men', 'nom', 'eno', 'ome', 'non', 'men', 'eno', 'non']
Total unique substring count: 7 list: set(['nom', 'non', 'ome', 'men', 'phe', 'eno', 'hen'])