mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-11 09:01:44 -04:00
Co-authored-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com> Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
2.0 KiB
2.0 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 681cb1b1dab50c87ddb2e51f | Python Challenge 5: Jbelmud Text | 29 | python-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".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(jbelmu("hello world"), "hello wlord")`)
}})
jbelmu("i love jumbled text") should return "i love jbelmud text".
({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".
({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".
({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--
def jbelmu(text):
return text
--solutions--
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)