# 4 lines Python solution

• Use `collections.Counter` and `itertools.permutations`

``````class Solution(object):
def generatePalindromes(self, s):
d = collections.Counter(s)
m = tuple(k for k, v in d.iteritems() if v % 2)
p = ''.join(k*(v/2) for k, v in d.iteritems())
return [''.join(i + m + i[::-1]) for i in set(itertools.permutations(p))] if len(m) < 2 else []``````

• Nice solution, you are quite familiar with Python!

• Not really...

• Nice one. Though we should really have a test case like `s = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'` ... (you'd get TLE, even though there is just a single possibility).

• Of course it's not optimal.

• Agree with stefan, and not sure if these advanced methods are ok for job interviews...

• I had a similar solution, but I got timeout for `s = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'`

``````    def generatePalindromes(self, s):
"""
:type s: str
:rtype: List[str]
"""
word_count = collections.Counter(s)
odd_char, odd_elemnts, compressed, result = '', 0, [], []
for w in word_count:
if word_count[w] % 2 == 1:
odd_elemnts += 1
odd_char = w
for _ in range(word_count[w] / 2):
compressed.append(w)
if odd_elemnts > 1:
return []

words_set = set()
for l in itertools.permutations(compressed):
word = ''.join(l)
if word not in words_set: