-1

I have a text like this:

a ab aba bob dod doood zoroz rar goog bnb

and I want to find the biggest symmetric word in this text. How can I do it?

I'm looking for the fastest way possible.

accdias
  • 5,160
  • 3
  • 19
  • 31
Keivan
  • 173
  • 2
  • 12

2 Answers2

1

Since I don't want to hand over the entire code to you, let me break it down :

Break the sentence down into a list of words 
Initialise a variable to hold the maximum length of the pallindrome (maxlen = 0)
Initialise a variable to hold the word with this lenght ( result = "" )
For word in list :
    if word is a pallindrome and length(word) > maxlen
        maxlen = length(word)
        result = word
Sruthi
  • 2,908
  • 1
  • 11
  • 25
0

Something like this will do it:

Python 3.7.5 (default, Oct 17 2019, 12:16:48) 
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> words = 'a ab aba bob dod doood zoroz rar goog bnb'
>>> max((word for word in words.split() if word == word[::-1]), key=len)
'doood'
>>>
accdias
  • 5,160
  • 3
  • 19
  • 31