Filter Valid Coupon Codes

Medium ⏱ 12 min 60% acceptance ★★★★★ 4.5
A coupon code is valid when it is exactly 6 characters, all uppercase alphanumeric, and does not start with a digit. Write valid_coupons(codes) filtering a list down to the valid ones with one comprehension (multiple if clauses or one combined condition).

Examples

Example 1
Input
valid_coupons(['SAVE20', '1BAD00', 'save20', 'FLASH5'])
Output
['SAVE20', 'FLASH5']
Explanation

1BAD00 starts with a digit; save20 is lowercase.

Constraints

  • Exactly 6 chars, isalnum, isupper letters, first char not a digit.
  • Single comprehension.

Topics

List Comprehensionsmultiple conditions

Companies

MyntraSwiggyRazorpay

Hints

Hint 1

Multiple if clauses in a comprehension AND together.

Hint 2

c[0].isdigit() detects the bad first character. Note: .isupper() on a string requires at least one cased character, which the no-leading-digit rule guarantees.

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