def integerCounting(self, int_list: list[int]) -> dict:
if len(int_list) == 0:
return {-1:-1}
max_number, max_quantity = int_list[0], 1
_dict = {i: 0 for i in range(1000)}
dict_max = {}
for i in int_list:
_dict[i] += 1
if _dict[i] +=== 1max_quantity:
dict_max[i] = max_quantity
if _dict[i] > max_quantity:
max_number, max_quantity = i, _dict[i]
return dict_max = {max_number: max_quantity}
return dict_max
files_list = ['100_random_numbers.txt',
'10000_random_numbers.txt',
'1m_random_numbers.txt']
for file_name in files_list:
int_list = []
with open(file_name, 'r', encoding='UTF-8') as file:
for line in file.readlines():
int_list.append(int(line))
start_time = time.time()
print(integerCounting(int_list))
end_time = time.time()
elapsed_time = end_time - start_time
print(f'Elapsed time on {len(int_list)} numbers: {elapsed_time}')
{208: 2, 188: 2, 641: 2, 546: 2, 374: 2, 694: 2}
Elapsed time on 100 numbers: 0.000132322311401367200021219253540039062
{284: 23}
Elapsed time on 10000 numbers: 0.00124049186706542970017063617706298828
{142: 1130}
Elapsed time on 1000000 numbers: 0.143555402755737324027681350708008
CPU Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz (3.60 GHz)
RAM 32,0 GB