-
Notifications
You must be signed in to change notification settings - Fork 0
/
all-the-same.py
61 lines (52 loc) · 1.48 KB
/
all-the-same.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
53
54
55
56
57
58
59
60
61
def are_all_same(arr):
if len(arr) == 0:
return True
else:
arr_set = set(arr)
if len(arr_set) <= 1:
return True
else:
return False
def secured_password(pwd):
import re
if len(pwd) >= 10:
l_char = re.search(r'[a-z]+', pwd)
u_char = re.search(r'[A-Z]+', pwd)
nums = re.search(r'[0-9]+', pwd)
if (l_char is not None and u_char is not None and nums is not None):
return True
else:
return False
else:
return False
def most_wanted_letter(words):
import re
ltr_frq = {}
frq_ltr = {}
filtered_words = re.findall(r'[a-zA-Z]]+', words)
text = ''.join(filtered_words)
for i in text:
ch = i.lower()
if ltr_frq.get(ch) is not None:
ltr_frq[ch] += 1
else:
ltr_frq[ch] = 1
if frq_ltr.get(ltr_frq[ch]) is not None:
frq_ltr[ltr_frq[ch]].append(ch)
else:
frq_ltr[ltr_frq[ch]] = [ch]
# Converting the keyset into list to enable sorting
frq_list = list(frq_ltr.keys())
# Sorting the letter frequency list
frq_list.sort()
# Greatest count list
grt_cnt_list = frq_ltr[frq_list[-1]]
if len(grt_cnt_list) > 1:
cloned = list(grt_cnt_list)
grt_cnt_list = sorted(cloned)
return grt_cnt_list[0]
def insert_into_dict(dct, el):
if dct.get(el) is not None:
dct[el] += 1
else:
dct[el] = 1