Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

66 lines
1.4 KiB
Markdown

---
id: 68b7cadffed0e75a517da66f
title: "Challenge 50: Longest Word"
challengeType: 29
dashedName: challenge-50
---
# --description--
Given a sentence, return the longest word in the sentence.
- Ignore periods (`.`) when determining word length.
- If multiple words are ties for the longest, return the first one that occurs.
# --hints--
`get_longest_word("coding is fun")` should return `"coding"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_longest_word("coding is fun"), "coding")`)
}})
```
`get_longest_word("Coding challenges are fun and educational.")` should return `"educational"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_longest_word("Coding challenges are fun and educational."), "educational")`)
}})
```
`get_longest_word("This sentence has multiple long words.")` should return `"sentence"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_longest_word("This sentence has multiple long words."), "sentence")`)
}})
```
# --seed--
## --seed-contents--
```py
def get_longest_word(sentence):
return sentence
```
# --solutions--
```py
def get_longest_word(sentence):
words = sentence.split()
longest = ''
for word in words:
clean_word = word.replace('.', '')
if len(clean_word) > len(longest):
longest = clean_word
return longest
```