-
Notifications
You must be signed in to change notification settings - Fork 5
/
ugly_code.py
52 lines (38 loc) · 1.25 KB
/
ugly_code.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
52
def pretty_function(string_to_count):
raise NotImplementedError()
def Ugly_Function(string_to_count):
Cpy_Of_String = str(string_to_count)
Result = {}#holds result
for c in Cpy_Of_String:
if (c in Result.keys()) == False:
Result[c] = [c]
elif (c in Result.keys()) == True:
a = Result[c]
a.append(c)
Result[c] = a
NormalResults = {}
for r, v in Result.items():
i = 0
for item in v:
i += 1
NormalResults[r] = i
print(NormalResults)
Result2= {}
for c in Cpy_Of_String:
if (c.lower() in Result2.keys()) == False:
Result2[c.lower()] = [c.lower()]
elif (c.lower() in Result2.keys()) == True:
a = Result2[c.lower()]
a.append(c.lower())
Result2[c.lower()] = a
smallresult = {}
for r, v in Result2.items():
i = 0
for item in v:
i += 1
smallresult[r] = i
print(smallresult)
if __name__ == '__main__':
string_to_count = 'Otters are COOL animals! The coolest!'
Ugly_Function(string_to_count)
# pretty_function(string_to_count)