Build a Dict from Two Parallel Lists

Easy ⏱ 8 min 76% acceptance ★★★★☆ 4.4
Write a function catalog_from_lists(ids, names) that takes two equal-length lists — product ids and product names — and returns a dict mapping each id to its corresponding name, using zip.

Examples

Example 1
Input
catalog_from_lists([101, 102, 103], ['Pen', 'Bag', 'Mug'])
Output
{101: 'Pen', 102: 'Bag', 103: 'Mug'}
Explanation

Pair up ids[i] with names[i].

Constraints

  • ids and names always have equal length.

Topics

Dictionarieszip()

Companies

WiproTCS

Hints

Hint 1

`dict(zip(ids, names))` builds the mapping directly.

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