0

I'm kind of a beginner, and no searches could answer my problem. I'm trying to find the longest word in a string if a word is defined as a set of English characters next to each other. Dictionaries not allowed, iI'm stuck on the splitting part with replacing non-alpha chars with spaces.

aperson
  • 11
  • 1
  • Please provide some example code of the problem, and your attempted solution. – jmd_dk Oct 23 '17 at 15:14
  • Possible duplicate of [Split string on whitespace in Python](https://stackoverflow.com/questions/8113782/split-string-on-whitespace-in-python) – Zulfiqaar Oct 23 '17 at 15:15
  • `max(re.split("[^a-z]+",target_text,re.I),key=len)` I guess... – Joran Beasley Oct 23 '17 at 15:15
  • The `str.translate` method is useful for replacing a bunch of chars in a string. Or you could just use a loop and `str.isalpha`. – PM 2Ring Oct 23 '17 at 15:16
  • @PM2Ring OP only thinks they need to replace with whitespace... as far as i can tell from problem statement you dont need to do that... – Joran Beasley Oct 23 '17 at 15:18
  • @JoranBeasley They need actual word lengths, so simply splitting on whitespace isn't enough. They need to deal with the punctuation chars too. Sure, they could do it your way, with a regex, but it's easy enough using `str` methods. – PM 2Ring Oct 23 '17 at 15:19
  • Please see [how-to-ask](https://stackoverflow.com/help/how-to-ask). Providing some code sample could go a long way. – scharette Oct 28 '17 at 01:51

0 Answers0