Skip to content

Instantly share code, notes, and snippets.

@AnnikaNoren
Created November 16, 2020 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnnikaNoren/35024aef4dcb2dbede01a333476126d5 to your computer and use it in GitHub Desktop.
Save AnnikaNoren/35024aef4dcb2dbede01a333476126d5 to your computer and use it in GitHub Desktop.
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