Skip to content

Latest commit

 

History

History
58 lines (33 loc) · 764 Bytes

File metadata and controls

58 lines (33 loc) · 764 Bytes

CodeWars Python Solutions


Exes and Ohs

Definition

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:

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

Given Code

def xo(s):
    pass

Solution 1

def xo(s):
    return (s.lower()).count("x") == (s.lower()).count("o")

Solution 2

def xo(s):
    return s.lower().count('x') == s.lower().count('o')

See on CodeWars.com