Enumerate a List With Index and Value

Easy ⏱ 8 min 74% acceptance ★★★★☆ 4.2
Write a function label_items(items) that returns a list of strings formatted as "index: value" for each element in items, using enumerate() in the loop rather than manually tracking an index counter.

Examples

Example 1
Input
label_items(["apple", "banana"])
Output
["0: apple", "1: banana"]
Explanation

Zero-based indices paired with values.

Constraints

  • items is a list.
  • Must use enumerate(), not a manual counter variable.

Topics

Loopsenumerate()

Companies

AdobeSalesforce

Hints

Hint 1

`for i, value in enumerate(items):` gives you both the index and the value.

Hint 2

Build each formatted string with an f-string.

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