Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from collections import Counter
def lcm_of_factors(list):
# empty dictionary
unique = {}
for i in range(0,len(list)):
number = list[i]
numbers = factors(number)
count = Counter(numbers)
for k,v in count.items():
if k not in unique:
unique[k] = v
elif k in unique and v > unique[k]:
unique[k] = v
else:
pass
# Tally the dictionary of keys and values
result = 1
for k,v in unique.items():
result = result * (k ** v)
print("The LCM of ", list, " is ", result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment