In Python language:
Create a function that takes as input two numbers, m and n, m<n, and returns an m×n list-of-list-of-numbers. Each element of the outer list will be a list of consecutive integers, beginning with 1 and ending with n−1. If you're feeling bold, try to use list comprehension.
All the explanation is in the comments of the code itself.
I have used line comprehension.
Code--
def listComprehension(m,n):
#initialize the matrix
matrix=[[row for row in range(n)] for i in range(m-1)]
#return the matrix
return matrix
print(listComprehension(4,3))
print(listComprehension(5,6))
Output--
Code Screenshot--
Note--
Please upvote if you like the effort.
Get Answers For Free
Most questions answered within 1 hours.