Matrix rows to a dictionary

EasyDictionary Programs · 55 of 94

Write a Python program to convert a matrix into a dictionary keyed by row number.

Advertisement
Input
[[1, 2, 3], [4, 5, 6]]
Output
{1: [1, 2, 3], 2: [4, 5, 6]}

Approach

  1. enumerate(matrix, start=1).

Solution

Python
matrix = [[1, 2, 3], [4, 5, 6]]print(dict(enumerate(matrix, start=1)))
Output
{1: [1, 2, 3], 2: [4, 5, 6]}

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs

Leave a Comment