Reading String type to find long "magic word"
![](https://secure.gravatar.com/avatar/5a06d009e55b9671ab8696d53418522f.jpg?s=120&d=mm&r=g)
Hello everybody, I just have one long string type:ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA The result I want to take is ArozaupalanalapuazorA - which means reading directly each letter should be the same as reading reversely ... Is there any function which can deals with this problem in Python??? Thanks for answer -- Bakhti
![](https://secure.gravatar.com/avatar/684759193c65bca9c850bb19b57d4c9a.jpg?s=120&d=mm&r=g)
Here's a seed for your function: s = 'ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA' f = np.array(list(s)).view('int8').astype(float) f -= f.mean() maybe_here = np.argmax(np.convolve(f,f))/2 magic = 10 print s[maybe_here - magic:maybe_here + magic + 1] Let us now how to assign significance to the result and to find optimal 'magic' Val On Fri, Apr 19, 2013 at 6:01 PM, Bakhtiyor Zokhidov < bakhtiyor_zokhidov@mail.ru> wrote:
Hello everybody,
I just have one long string type:ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA
The result I want to take is ArozaupalanalapuazorA - which means reading directly each letter should be the same as reading reversely ...
Is there any function which can deals with this problem in Python???
Thanks for answer
-- Bakhti
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
![](https://secure.gravatar.com/avatar/5a06d009e55b9671ab8696d53418522f.jpg?s=120&d=mm&r=g)
Hi, I am a bit unaware with that you put magic = 10 . Why? Пятница, 19 апреля 2013, 19:05 -05:00 от Val Kalatsky <kalatsky@gmail.com>:
Here's a seed for your function:
s = ' Thesampletextthatcouldbereaded thesameinbothordersArozaupalan alapuazorA ' f = np.array(list(s)).view('int8').astype(float) f -= f.mean() maybe_here = np.argmax(np.convolve(f,f))/2 magic = 10 print s[maybe_here - magic:maybe_here + magic + 1]
Let us now how to assign significance to the result and to find optimal 'magic'
Val
On Fri, Apr 19, 2013 at 6:01 PM, Bakhtiyor Zokhidov < bakhtiyor_zokhidov@mail.ru > wrote:
Hello everybody,
I just have one long string type:ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA
The result I want to take is ArozaupalanalapuazorA - which means reading directly each letter should be the same as reading reversely ...
Is there any function which can deals with this problem in Python???
Thanks for answer
-- Bakhti _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Bakhtiyor Zokhidov
-
Val Kalatsky