-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexes_and_ohs.py
More file actions
29 lines (25 loc) · 850 Bytes
/
Copy pathexes_and_ohs.py
File metadata and controls
29 lines (25 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def xo(s):
"""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 contains 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
"""
# no_of_x = 0
# no_of_o = 0
# for symbol in s:
# if symbol == 'x': # don't use "is" pto compare two different objects
# no_of_x += 1
# elif symbol == 'o':
# no_of_o += 1
# if no_of_o == no_of_x:
# return True
# else:
# return False
s = s.lower()
return s.count('x') == s.count('o') # there is count method for string and # lists