-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrequency guide.py
More file actions
30 lines (22 loc) · 1018 Bytes
/
Copy pathfrequency guide.py
File metadata and controls
30 lines (22 loc) · 1018 Bytes
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
user_input = input("Please Input a word: ")
count = [None] * len(user_input);
for i in range(0, len(user_input)):
count[i] = 1;
for j in range(i+1, len(user_input)):
if(user_input[i] == user_input[j]):
count[i] = count[i] + 1;
#Set string[j] to 0 to avoid printing visited character
user_input = user_input[ : j] + '0' + user_input[j+1 : ];
#Displays the each character and their corresponding frequency
print("Characters and their corresponding frequencies");
for i in range(0, len(count)):
if(user_input[i] != ' ' and user_input[i] != '0'):
print(user_input[i] + " - " + str(count[i]));
"""user_input = input("Please Input a word: ")
char_count = {}
for char in range(0,len(user_input)):
if char in char_count:
char_count[char] += 1
else:
char_count[char] = 1
print ("Count of all characters in user input:\n " + str(char_count))"""