Zip Two Lists Into Pairs and a Dict

Easy ⏱ 8 min 86% acceptance ★★★★★ 4.8
Write pair_names_and_scores(names, scores) that combines two equal-length lists into a list of (name, score) tuples using zip(), then also returns a dictionary built from those pairs. Return a tuple (pairs_list, pairs_dict).

Examples

Example 1
Input
names = ['Ana', 'Bo'], scores = [90, 75]
Output
([('Ana', 90), ('Bo', 75)], {'Ana': 90, 'Bo': 75})
Explanation

zip() pairs elements positionally; dict() turns pairs into a mapping.

Constraints

  • len(names) == len(scores)
  • 0 <= len(names) <= 10^4

Topics

ListsZipping

Companies

MetaLinkedIn

Hints

Hint 1

list(zip(names, scores)) gives the pairs.

Hint 2

dict(zip(names, scores)) 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.