본문 바로가기
프로그래밍 문제/[Python] CheckIO

[CheckIO] Convert To Title case

by Physics 2024. 2. 18.
728x90

1. Problem: https://py.checkio.org/en/mission/convert-to-title-case/
2. My solutions

def to_title_case(sentence: str) -> str:
    # your code here
    return ' '.join([data.capitalize() for data in sentence.lower().split()])


print("Example:")
print(to_title_case("hello world"))

# These "asserts" are used for self-checking
assert to_title_case("hello world") == "Hello World"
assert to_title_case("openai gpt-4") == "Openai Gpt-4"
assert to_title_case("this is a title") == "This Is A Title"
assert to_title_case("THE QUICK BROWN FOX") == "The Quick Brown Fox"
assert to_title_case("JUMPs ovER a LAZy dog") == "Jumps Over A Lazy Dog"
assert to_title_case("typescript is great") == "Typescript Is Great"
assert to_title_case("the answer is 42") == "The Answer Is 42"
assert to_title_case("to be or not to be") == "To Be Or Not To Be"
assert to_title_case("that is the question") == "That Is The Question"
assert to_title_case("") == ""

 

728x90

댓글