easy +8 pts

Initials from a Full Name

Extract the uppercase initials from a person's full name.

Write a function `get_initials(name: str) -> str` that takes a full name as a string and returns a string consisting of the first character of each word in the name, converted to uppercase. Words are separated by one or more spaces. The input may contain leading or trailing spaces. If the name is empty or contains only spaces, return an empty string. For example: - `get_initials("john fitzgerald kennedy")` should return `"JFK"`. - `get_initials(" Ada Lovelace ")` should return `"AL"`.

Constraints

- The input string length is between 0 and 1000. - The name contains only letters and spaces (no punctuation or digits). - Words are separated by one or more spaces. - Expected time complexity: O(n), where n is the length of the input string.

Example

>>> get_initials("john fitzgerald kennedy")
'JFK'
>>> get_initials("  Ada   Lovelace ")
'AL'
>>> get_initials("")
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use the `split()` method to break the string into words, ignoring extra spaces.
Iterate over the words and take the first character of each.
Convert each first character to uppercase using the `upper()` method.
Join the uppercase characters together with `''.join()`.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.