Check to see if a string has the same amount of 'x’s and 'o’s. The method must return a boolean and be case insensitive. The string can contain any char.
Examples input/output:
XO("ooxx") => true
XO("xooxx") => false
XO("ooxXm") => true
XO("zpzpzpp") => true
// when no 'x' and 'o' is present should return true
XO("zzoo") => false
Solution :
def xo(s):
list_o = []
list_x = []
test_string = s.lower()
for letter in test_string:
if letter == "o":
list_o.append(letter)
elif letter == "x":
list_x.append(letter)
count_o = len(list_o)
count_x = len(list_x)
if count_o != count_x:
return False
return True