#56MediumLists & Tuples· Comprehensions
List Comprehension Challenges
Input format
`grid`: a list of lists whose items are integers or `None`.
Output format
A dictionary with keys `flat`, `even_squares` and `row_sums`.
Examples
Input: grid = [[1,2,null],[4,null,6]]
Output: {"flat":[1,2,4,6],"even_squares":[4,16,36],"row_sums":[3,10]}
Reading order skips the two `None` values; 2, 4 and 6 are even.
Input: grid = [[null],[],[-3,-4]]
Output: {"flat":[-3,-4],"even_squares":[16],"row_sums":[0,0,-7]}
-4 is even, so 16 is included. The first two rows sum to 0.
Constraints
- 0 <= len(grid) <= 100
- 0 <= len(row) <= 100
- -1000 <= reading <= 1000
Study first
- #python
- #list-comprehensions
- #nested-lists
