-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShifter words
25 lines (17 loc) · 1.31 KB
/
Shifter words
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
You probably know that some characters written on a piece of paper, after turning this sheet 180 degrees, can be read, although sometimes in a different way. So, uppercase letters "H", "I", "N", "O", "S", "X", "Z" after rotation are not changed, the letter "M" becomes a "W", and Vice versa, the letter "W" becomes a "M".
We will call a word "shifter" if it consists only of letters "H", "I", "N", "O", "S", "X", "Z", "M" and "W". After turning the sheet, this word can also be read, although in a different way. So, the word "WOW "turns into the word "MOM". On the other hand, the word "HOME" is not a shifter.
Find the number of unique shifter words in the input string (without duplicates). All shifters to be counted, even if they are paired (like "MOM" and "WOW"). String contains only uppercase letters.
Examples
shifter("SOS IN THE HOME") == 2 # shifter words are "SOS" and "IN"
shifter("WHO IS SHIFTER AND WHO IS NO") == 3 # shifter words are "WHO", "IS", "NO"
shifter("TASK") == 0 # no shifter words
shifter("") == 0 # no shifter words in empty string
Python
def shifter(st):
# your code here
a=0
for x in (list(set((list(st.split()) )))):
if set(x) <= set('HINOSXZMW'):a+=1
return a
def shifter(st):
return sum(all(elem in "HIMNOSWXZ" for elem in x) for x in set(st.split()))