Created
December 9, 2019 00:32
-
-
Save Angeldude/f9651b42cc9ed9ae698223d12c495276 to your computer and use it in GitHub Desktop.
A function to check if a string can be re-arranged into a palindrome.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def can_make_palindrome2(string): | |
letters = set(string) | |
length = len(string) | |
if length & 1: | |
temp = map(lambda x: string.count(x) & 1, letters) | |
return any(temp) and not(any(temp)) | |
else: | |
return all(map(lambda x: not(string.count(x) & 1), letters)) | |
print(can_make_palindrome2("boob")) | |
print(can_make_palindrome2("boobs")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment