Every Size-Color Variant

Medium ⏱ 12 min 52% acceptance ★★★★★ 4.9
A t-shirt comes in several sizes and colors. Write variants(sizes, colors) producing every "size-color" combination string, sizes varying slowest, using one comprehension with two for clauses.

Examples

Example 1
Input
variants(['S', 'M'], ['red', 'blue'])
Output
['S-red', 'S-blue', 'M-red', 'M-blue']
Explanation

Each size pairs with each color.

Constraints

  • Sizes iterate in the outer position.
  • Use an f-string or concatenation for the label.

Topics

List Comprehensionscartesian product

Companies

MyntraFlipkartAmazon

Hints

Hint 1

Two for clauses in one comprehension form a cross product.

Hint 2

The first for is the slow-moving one.

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