palindrome

Peter Otten __peter__ at web.de
Tue Nov 17 04:48:36 EST 2015


Abhiram R wrote:

> ​Haha. Nice. Although with your length of string and the range you're
> picking from,the chances of you getting a palindrome are (1/24!)  :D ​

Are you sure?

>>> candidates = list(itertools.product(string.ascii_lowercase, repeat=4))
>>> len(candidates)/len([c for c in candidates if c == c[::-1]])
676.0

That looks like one in 26**(length//2)




More information about the Python-list mailing list