using Javascript, we solve the Exes and Ohs problem on codewars
Пікірлер: 5
@KaranPatel-gl4zo7 ай бұрын
Could you show us it in python? This is the farthest i got but i fail the last test to return true if the string is empty or None: def xo(s): news = s.lower() for char in news: if not "x" and "o": return True elif news.count("x") == news.count("o"): return True elif news == None: return True else: return False
@wrttech4227 ай бұрын
Just do this: def xo(s): s = s.lower() return s.count('x') == s.count('o')
@ParasProgramming12311 ай бұрын
Why did you do +1 in count function
@wrttech42211 ай бұрын
The acc variable keeps track of the frequency of x and o in our array. Each time value is equal to x or o, we add 1 to the acc variable. The reduce function returns the acc variable at the end after iterating through each element in the array.