Created
November 16, 2020 16:06
-
-
Save AnnikaNoren/35024aef4dcb2dbede01a333476126d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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