Ad

I add up the ascii values of the string. the result % 324 (ie ord('f') + 2 * ord('o') should be zero.

there is also the case where the list is empty, checked by converting the length to a bool (implicitly).

Code
Diff
  • class KumiteFoo:
        def __init__(self, p):
            self.p = p
        
        def solution(self):
            return 'Yes' if len(self.p) and not sum(map(ord, self.p.lower()))%324 else 'No'
    
    • class KumiteFoo:
    • def __init__(self, p):
    • self.p = p
    • def solution(self):
    • f = self.p.lower().count('f')
    • o = self.p.lower().count('o')
    • return 'No' if not self.p or 2 * f != o else 'Yes'
    • return 'Yes' if len(self.p) and not sum(map(ord, self.p.lower()))%324 else 'No'
Code
Diff
  • binary=lambda n:f'{n:b}'
    • binary=lambda n:bin(n)[2:]
    • binary=lambda n:f'{n:b}'