-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrackutils.py
51 lines (44 loc) · 1.2 KB
/
crackutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
from operator import itemgetter
def unique(inlist, keepstr=True):
typ = type(inlist)
if not typ == list:
inlist = list(inlist)
i = 0
while i < len(inlist):
try:
del inlist[inlist.index(inlist[i], i + 1)]
except:
i += 1
if not typ in (str, unicode):
inlist = typ(inlist)
else:
if keepstr:
inlist = ''.join(inlist)
return inlist
def freqCount(instring,sort=False):
ustring = unique(instring)
freqdict = {}
for ch in ustring:
num = instring.count(ch)
freqdict[ch] = num
return freqdict
def printFreq(freqdict,reverse=False,alphabetical=False):
keys = freqdict.keys()
if not alphabetical:
d2 = sorted(freqdict.iteritems(),key=itemgetter(1),reverse=reverse)
for d in d2:
k = d[0]
v = d[1]
if '"' in keys:
print "'%s':%i" % (k,v)
if "'" in keys:
print '"%s":%i'% (k,v)
else:
keys = sorted(freqdict.keys())
for k in keys:
v = freqdict[k]
if '"' in keys:
print "'%s':%i" % (k,v)
if "'" in keys:
print '"%s":%i'% (k,v)