def lcm_list(t,a,list0,num): #重构出来的函数,用于筛查出被a的数且小于num
while t < num:
t += 1
if t%a == 0:
list0.append(t)
def LCM(nums):
if len(nums) == 2: #当nums数列为两个元素时
x = nums[0]
y = nums[1]
num = x*y
list1 = []
list2 = []
list4 = []
t1 = x - 1
t2 = y - 1
lcm_list(t1,x,list1,num)
lcm_list(t2,y,list2,num)
length = len(list1)
for i in range(length):
if list1[i] in list2:
list4.append(list1[i]) #(用的传统形式)对两个列表的相同的元素进行筛选保存到list4列表中
if len(nums) == 3: #当nums数列为三个元素时
x = nums[0]
y = nums[1]
z = nums[2]
num = x*y*z
list1 = []
list2 = []
list3 = []
list4 = []
t1 = x
t2 = y
t3 = z
lcm_list(t1,x,list1,num)
lcm_list(t2,y,list2,num)
lcm_list(t3,z,list3,num)
length = len(list1)
list4 = [list1[i] for i in range(length) if list1[i] in list2 if list1[i] in list3] #(用三元操作符)对三个个列表的相同的元素进行筛选保存到list4列表中
return list4[0]
print (LCM([4, 8]))