-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.py
33 lines (33 loc) · 1.09 KB
/
sample.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
## initializing the lists
words = ["hi", "hello", "bye", "good"]
characters = ["h", "i", "b", "y", "e"]
## function which returns dictionary containing char counts
def char_count(word):
## initializing an empty dictionary
char_count = {}
## loop to find the frequency of the chars
for char in word:
## incrementing the char count by one
char_count[char] = char_count.get(char, 0) + 1
## returning dictionary
return char_count
## iterating through the words list
for word in words:
## initializing flag to one
flag = 1
## getting the char count using char_count() function
chars = char_count(word)
## iterating through the chars
for key in chars:
## checking for the presence of key in the characters
if key not in characters:
## updating the flag value to zero
flag = 0
else:
## comparing the count of chars in chars and characters
if characters.count(key) != chars[key]:
## updating the flag value to zero
flag = 0
## checking the flag value
if flag == 1:
print(word)