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

2.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69f35a5bb823ed620fcb7cbd Challenge 284: I Before E 29 challenge-284

--description--

Given a word or sentence, return a corrected version where every word follows the "I before E except after C" rule.

  • If a word contains "ei" not preceded by "c", replace it with "ie".
  • If a word contains "ie" preceded by "c", replace it with "ei".
  • All other words are left unchanged.

--hints--

i_before_e("beleive") should return "believe".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(i_before_e("beleive"), "believe")`)
}})

i_before_e("recieve") should return "receive".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(i_before_e("recieve"), "receive")`)
}})

i_before_e("we recieved a breif") should return "we received a brief".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(i_before_e("we recieved a breif"), "we received a brief")`)
}})

i_before_e("she beleived the friendly niece could percieve the greif") should return "she believed the friendly niece could perceive the grief".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(i_before_e("she beleived the friendly niece could percieve the greif"), "she believed the friendly niece could perceive the grief")`)
}})

i_before_e("we recieved relief after the theif gave us a breif piece of feirce deceit") should return "we received relief after the thief gave us a brief piece of fierce deceit".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(i_before_e("we recieved relief after the theif gave us a breif piece of feirce deceit"), "we received relief after the thief gave us a brief piece of fierce deceit")`)
}})

--seed--

--seed-contents--

def i_before_e(sentence):

    return sentence

--solutions--

import re

def i_before_e(sentence):
    words = []
    for word in sentence.split(" "):
        word = re.sub(r"([^c])ei", r"\1ie", word)
        word = re.sub(r"cie", "cei", word)
        words.append(word)
    return " ".join(words)