Validate a Three-Part Word Label
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
label = "anna martin lee"Truelabel = "x do by"Truelabel = "maria stone park"TrueConstraints
1 <= len(label) <= 25label contains lowercase letters and spaces- Types:
labelis str; result is bool
Function signature
def is_valid_word_label(label: str) -> bool
labelstr- 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.