Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Case Conversion Coding Task

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

Your question is Case Conversion Coding Task. 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

Exusia's text-processing utilities need to emphasize the boundaries of every word in a line. Given a string, capitalize the first and last ASCII alphabetic character of each whitespace-delimited token, while preserving all other characters, capitalization, punctuation, and whitespace.

A token may contain punctuation or digits. For example, in (hello),, the letters h and o are the word edges. Tokens containing no alphabetic characters remain unchanged. If a token contains one alphabetic character, capitalize it once.

Formal Specification

Implement capitalize_word_edges(line), where line is a string. Return a new string with the required capitalization. Do not modify the order or number of characters.

Constraints

  • 0 <= len(line) <= 10^5
  • The input contains ASCII characters.
  • A word is a maximal sequence of non-whitespace characters.
  • Only A-Z and a-z are considered alphabetic.

Function Signature

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