Extract Numeric Ticket IDs

Hard ⏱ 18 min 29% acceptance ★★★★★ 4.7
Ticket references look like 'TKT-1043', 'BUG-77', or are malformed. Write ticket_numbers(refs) that pulls the integer part from every reference matching the PREFIX-DIGITS shape (letters, one hyphen, digits) and skips everything else — comprehension only, no regex.

Examples

Example 1
Input
ticket_numbers(['TKT-1043', 'oops', 'BUG-77', 'X-Y-9'])
Output
[1043, 77]
Explanation

'oops' has no hyphen; 'X-Y-9' has two.

Constraints

  • No re module.
  • Exactly one hyphen; left part alphabetic, right part numeric.

Topics

List Comprehensionsstring parsing

Companies

ServiceNowAtlassianIBM

Hints

Hint 1

r.count('-') == 1 guards the split.

Hint 2

Use partition or split, then .isalpha() / .isdigit() checks.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.