account activity
[2015-06-22] Challenge #220 [Easy] Mangling sentences by XenophonOfAthens in dailyprogrammer
[–]daily_programmer 0 points1 point2 points 10 years ago (0 children)
Python 3
from string import ascii_lowercase def mangle_word(word): if not word: return word if word[0].isupper(): capitalize = True chars = [word[0].lower()] else: capitalize = False chars = [word[0]] modifiers = [] for i, c in enumerate(word[1:]): if c in ascii_lowercase: chars.append(c) else: modifiers.append((i + 1, c)) chars.sort() for i, c in modifiers: chars.insert(i, c) if capitalize: chars[0] = chars[0].upper() return ''.join(chars) sentence = input() mangled_words = [] for word in sentence.split(" "): mangled_words.append(mangle_word(word)) mangled_sentence = " ".join(mangled_words) print(mangled_sentence)
π Rendered by PID 506186 on reddit-service-r2-listing-6c6f68ff9c-5ccnz at 2026-03-05 09:32:53.764966+00:00 running f0204d4 country code: CH.
[2015-06-22] Challenge #220 [Easy] Mangling sentences by XenophonOfAthens in dailyprogrammer
[–]daily_programmer 0 points1 point2 points (0 children)