+ 1
How to find the common factors of two numbers? Can I use set operations or list operations to do this?
# 56 = 2 × 2 × 2 × 7 #78 = 2 × 3 × 13 a = {2, 2, 2, 7} b = {2, 3, 13} print(a & b) Output: {2, 3} It doesn't return all the 2 and 3
3 Réponses
+ 1
It doesn't return what u want bcuz u put those factors in a and b which are SETs.
Sets automatically remove duplicated items.
if u print a u will have ---> {2,7}
Put your factors in list instead.
0
But, list doesn't have union, intersection operations
0
Neethu Nath You can write your own codes for that purpose. Define a func for Union.