mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update check_permutation_strings_is_palindrome.py
This commit is contained in:
parent
b81ccd579b
commit
2fe4c94c7f
@ -2,8 +2,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# author: bt3gl
|
# author: bt3gl
|
||||||
|
|
||||||
# given a string, write a function to check if it's a permutation of palindromes
|
|
||||||
|
|
||||||
|
|
||||||
def is_permutation_of_palindromes(some_string):
|
def is_permutation_of_palindromes(some_string):
|
||||||
|
|
||||||
@ -11,27 +9,13 @@ def is_permutation_of_palindromes(some_string):
|
|||||||
|
|
||||||
for c in some_string.strip():
|
for c in some_string.strip():
|
||||||
|
|
||||||
# note: you could use a Counter dict here
|
|
||||||
if c in aux_dict.keys():
|
if c in aux_dict.keys():
|
||||||
aux_dict[c] -= 1
|
aux_dict[c] -= 1
|
||||||
else:
|
else:
|
||||||
aux_dict[c] = 1
|
aux_dict[c] = 1
|
||||||
|
|
||||||
for v in aux_dict.values():
|
for v in aux_dict.values():
|
||||||
|
|
||||||
if v != 0:
|
if v != 0:
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
|
|
||||||
string1 = "abba"
|
|
||||||
string2 = "ab f ab"
|
|
||||||
string3 = "e f ba"
|
|
||||||
|
|
||||||
assert(is_permutation_of_palindromes(string1) == True)
|
|
||||||
assert(is_permutation_of_palindromes(string2) == True)
|
|
||||||
assert(is_permutation_of_palindromes(string3) == False)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user