Skip to content

Instantly share code, notes, and snippets.

@Angeldude
Created December 9, 2019 00:32
Show Gist options
  • Save Angeldude/f9651b42cc9ed9ae698223d12c495276 to your computer and use it in GitHub Desktop.
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.
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