+ 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

9th Nov 2021, 4:28 AM
Neethu Nath
Neethu Nath - avatar
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.
9th Nov 2021, 11:13 AM
Mosi B.
Mosi B. - avatar
0
But, list doesn't have union, intersection operations
9th Nov 2021, 11:54 AM
Neethu Nath
Neethu Nath - avatar
0
Neethu Nath You can write your own codes for that purpose. Define a func for Union.
9th Nov 2021, 6:19 PM
Mosi B.
Mosi B. - avatar