Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Capitalize Every String Letter

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Capitalize Every String Letter. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

CentralSquare Public Safety Suite may need incident text normalized before it is displayed or logged. Implement a function that converts every letter in a string to uppercase while leaving spaces, digits, punctuation, and other non-letter characters unchanged.

Formal Specification

Given a Python string text, return a new string containing the uppercase version of every letter in text. The input may contain lowercase letters, uppercase letters, whitespace, digits, punctuation, and Unicode characters. Do not modify the original string, and do not remove or reorder characters.

Examples

Example 1:

Input: text = "Unit 12: respond to Main St."
Output: "UNIT 12: RESPOND TO MAIN ST."

Letters become uppercase, while the space, digits, colon, and period remain unchanged.

Example 2:

Input: text = "Report #a-17 complete!"
Output: "REPORT #A-17 COMPLETE!"

Only alphabetic characters change; #, -, and 17 are preserved.

Constraints

  • 0 <= len(text) <= 10^5
  • text is a valid Python string.
  • The output must have the same number and order of characters as the input.
  • An empty string is valid input.

Constraints

  • 0 <= len(text) <= 10^5
  • text is a valid Python string
  • The output has the same character order as the input
  • An empty string is valid input

Function Signature

def capitalize_text(text):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output