To check each digit you need to convert these number in string-object
and then
count each digit from other number which result 0 or some finite number
and then using all
we can check that all digit is present their or not.
Check out this code:
def same_digits(a: int, b: int)->bool:
cond1 = all([str(b).count(i) for i in str(a)])
cond2 = all([str(a).count(i) for i in str(b)])
if cond1 and cond2:
return True
else:
return False
print(same_digits(998, 892))
OUTPUT:
False
Method-2
Use set
operation and sorting
for that purpose.
def same_digits(a: int, b: int)->bool:
if sorted(set(str(a))) == sorted(set(str(a))):
return True
return False
print(same_digits(998, 89))
3
solved How to determine whether the same digits appear in two integers? [closed]