Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/681cb1afdab50c87ddb2e516.md
T
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

82 lines
2.0 KiB
Markdown

---
id: 681cb1afdab50c87ddb2e516
title: "Challenge 5: Jbelmud Text"
challengeType: 29
dashedName: challenge-5
---
# --description--
Given a string, return a jumbled version of that string where each word is transformed using the following constraints:
- The first and last letters of the words remain in place
- All letters between the first and last letter are sorted alphabetically.
- The input strings will contain no punctuation, and will be entirely lowercase.
# --hints--
`jbelmu("hello world")` should return `"hello wlord"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(jbelmu("hello world"), "hello wlord")`)
}})
```
`jbelmu("i love jumbled text")` should return `"i love jbelmud text"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(jbelmu("i love jumbled text"), "i love jbelmud text")`)
}})
```
`jbelmu("freecodecamp is my favorite place to learn to code")` should return `"faccdeeemorp is my faiortve pacle to laern to cdoe"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(jbelmu("freecodecamp is my favorite place to learn to code"), "faccdeeemorp is my faiortve pacle to laern to cdoe")`)
}})
```
`jbelmu("the quick brown fox jumps over the lazy dog")` should return `"the qciuk borwn fox jmpus oevr the lazy dog"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(jbelmu("the quick brown fox jumps over the lazy dog"), "the qciuk borwn fox jmpus oevr the lazy dog")`)
}})
```
# --seed--
## --seed-contents--
```py
def jbelmu(text):
return text
```
# --solutions--
```py
def jbelmu(text):
words = text.split()
jumbled = []
for word in words:
if len(word) <= 3:
jumbled.append(word)
else:
first = word[0]
last = word[-1]
middle = ''.join(sorted(word[1:-1]))
jumbled.append(first + middle + last)
return ' '.join(jumbled)
```