Skip to content

Commit 525d877

Browse files
updates question 1.2,1.3,1.4. Adding 1.5 start
1 parent f4d85ca commit 525d877

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Palindrome Permutation: Given a string, write a function to check if it is a
3+
permutation of a palin­ drome. A palindrome is a word or phrase that is the same
4+
forwards and backwards. A permutation is a rearrangement of letters.
5+
The palindrome does not need to be limited to just dictionary words.
6+
EXAMPLE
7+
Input: Tact Coa
8+
Output: True (permutations: "taco cat", "atco eta", etc.)
9+
"""
10+
11+
def PalinPerm(str):
12+
d = {}
13+
str = str.replace(' ','').lower()#Take out the spaces
14+
for i in str:
15+
if i in d:
16+
d[i] += 1
17+
else:
18+
d[i] = 1
19+
odd_count = 0 # pop ppo opp
20+
for keys,value in d.items():
21+
if value % 2 != 0 and odd_count == 0:# Remeber there should only be 1 where key equals when val%2
22+
odd_count += 1
23+
elif value % 2 != 0 and odd_count != 0:
24+
return False
25+
return True
26+
27+
print(PalinPerm('taco cat'))#True
28+
print(PalinPerm('taco catt'))#False

0 commit comments

Comments
 (0)