forked from CodeToExpress/dailycodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrequency_counter.py
More file actions
31 lines (25 loc) · 767 Bytes
/
frequency_counter.py
File metadata and controls
31 lines (25 loc) · 767 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
31
"""
author: @aaditkamat
date: 15/01/2019
"""
def count_frequencies(lst):
frequency_dictionary = {}
for num in lst:
if num not in frequency_dictionary:
frequency_dictionary[num] = 1
else:
frequency_dictionary[num] += 1
for key in frequency_dictionary:
print(f'\'{key}\' is present {frequency_dictionary[key]} time(s)')
def get_input(word):
print(f'Enter {word} input array: ', end='')
input_array = input()
return input_array
def handle_input(word):
input_array = get_input(word)
return convert_input_array_to_list(input_array)
def convert_input_array_to_list(input_array):
return list(map(lambda x: int(x), input_array.strip('[').strip(']').split(',')))
def main():
lst = handle_input('an')
count_frequencies(lst)