Answers for "python nested list comprehension"

1

python nested list comprehension

matrix = [[j for j in range(5)] for i in range(5)]
Posted by: Guest on December-22-2020
0

nested loop in list comprehension

# 2-D List 
matrix = [[1, 2, 3], [4, 5], [6, 7, 8, 9]] 
  
# Nested List Comprehension to flatten a given 2-D matrix 
flatten_matrix = [val for sublist in matrix for val in sublist] 
  
print(flatten_matrix)
Posted by: Guest on November-05-2020

Code answers related to "python nested list comprehension"

Python Answers by Framework

Browse Popular Code Answers by Language