You are viewing a single comment's thread. Return to all comments →
Python with comprehension lists, for each number between max(setA) and min(setB), it will create a list that will hold boolean values, and 'all' checks that all the boolean values in a list are true.
lenA, lenB = map(int, raw_input().split())
setA = map(int, raw_input().split())
setB = map(int, raw_input().split())
maxA = max(setA)
minB = min(setB)
count = 0
for num in range(maxA, minB + 1):
left = all([num % numA == 0 for numA in setA])
right = all([numB % num == 0 for numB in setB])
count += left*right
Was unaware of the all function. I was trying something similar to this with list comprehensions nested in a for loop, but I was removing options from a list within the range. I understood the question, but had no concept of the methods I should use to compare every element returning True. Appreciate the knowledge. I agree with the commenter below, found this pretty difficult.
Here is a documentation defintion from Python that defines the all and any function. Pretty useful.