PracticeStrings

Validate a Three-Part Word Label

EasyStringstraversalstate trackingaccumulation Time not estimated Not started

Context

In a collection of pure strings, a label is valid only if it follows one precise arrangement. The label has three ordered lowercase components, with one space between neighboring components. Each component has its own length interval, and no characters may appear before, after, or between the prescribed parts.

Problem

Write a function that decides whether label is valid.

A valid label must contain exactly three components separated by exactly one space on each side of the middle separator. The first component has 1 to 8 lowercase letters, the second has 2 to 10 lowercase letters, and the final component has 2 to 5 lowercase letters. The complete string must consist only of these components and separators. Reject an empty string, missing or repeated separators, uppercase letters, digits, punctuation, extra spaces, and any component outside its allowed length.

Examples

Example 1
Input: label = "anna martin lee"
Output: True
Explanation: For "anna martin lee", the executed result is true; the final traced state has match_status true and component_index 2 with component_length 3.
Example 2
Input: label = "x do by"
Output: True
Explanation: For "x do by", the executed result is true; the final traced state has match_status true and component_index 2 with component_length 2.
Example 3
Input: label = "maria stone park"
Output: True
Explanation: For "maria stone park", the executed result is true; the final traced state has match_status true and component_index 2 with component_length 4.

Constraints

  • 1 <= len(label) <= 25
  • label contains lowercase letters and spaces
  • Types: label is str; result is bool

Function signature

def is_valid_word_label(label: str) -> bool
label str
The candidate three-part lowercase label.
returns bool
Return True exactly when the entire label matches the required three-component format and all component lengths are valid; otherwise return False.

Adapted from MBPP problem task_774 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Approved · cb048r1-abs_174_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1