Hi I have updated this with my code:
Input ->
a=[16,21, 56, 40]
def find_primes(a):
num_factors=[]
for num in a:
# print('1',num)
list_of_factors=[]
i=2
while num>1:
#print('2',num)
if num%i==0:
list_of_factors.append(i)
# print('3',list_of_factors)
num=num/i
# print('4',num)
i=i-1
i+=1
num_factors.append(list_of_factors)
d = {}
a_list = []
for i in num_factors:
for j in i:
d[j] = d.get(j, 0) + 1
dictionary_copy = d.copy()
a_list.append(dictionary_copy)
print(a_list)
return num_factors
find_primes(a)
This is the output I am getting:
[{2: 10, 3: 1, 7: 2, 5: 1}]
[[2, 2, 2, 2], [3, 7], [2, 2, 2, 7], [2, 2, 2, 5]]
Here is my question:
Understand since it is a dictionary, the value for the key accumulates.
I want to have the count of unique integers from each list. For eg. [{2:4},{3:1,7:1},{2:3,7:1},{2:3,5:1}] instead of what is given in the output from the code above.
After which, I want to get the max occurrence for each of the integers to calculate the LCM. 2^4 * 3 * 7 * 5
Kindly advise on how we could improve on the code. Appreciate the help.
This could be one of the approach.
That can be done in the following way: