def create_matrix(lst): """Create matrix will take matrix represented as a list of list. And output a function which will index the input matrix Not allowed to Import Libraries Args: lst (List of List): A list of list representation of matrix. There will be more than one element of list type in lst. Returns: [function]: An indexing function. >>> matrix_index1 = create_matrix([[1, 2], [2, 3]]) # a 2 x 2 matrix. >>> matrix_index2 = create_matrix([[1, 2, 3], [2, 3, 1]]) # a 2 x 3 matrix. >>> matrix_index3 = create_matrix([[1, 2, 3], []]) # an invalid matrix """ ### Modify your code here def matrix_index(i=None, j=None): """Indexing function which will retrive (i, j) entry of the input matrix representation Args: i (int, optional): row index. Defaults to None. (0-index) j (int, optional): column index. Defaults to None. (0-index) Return: List of List: a list of list representation of the indexed. Return None if matrix or index is invalid >>> matrix_index1() [[1, 2], [2, 3]] >>> matrix_index1(i=1) # row 1 (2nd row since 0 indexed) [[2, 3]] >>> matrix_index1(j=1) # col 1 (2nd row since 0 indexed) [[2], [3]] >>> matrix_index1(i=1, j=1) [[3]] >>> print(matrix_index1(i=1, j=10)) None # invalid index >>> print(matrix_index3()) None # invalid matrix """ ### Modify your code here
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
![270
def create_matrix(1st):
271
"*"Create matrix will take matrix represented as a list of list.
272
And output a function which will index the input matrix
273
Not allowed to Import Libraries
274
Args:
275
1st (List of List): A list of list representation of matrix.
276
There will be more than one element of list type in 1st.
277
278
Returns:
279
[function]: An indexing function.
280
281
>> matrix_index1 = create_matrix([[1, 2], [2, 3]]) # a 2 x 2 matrix.
create_matrix([[1, 2, 3], [2, 3, 1]]) # a 2 x 3 matrix.
create_matrix([[1, 2, 3], []]) # an invalid matrix
282
>>> matrix_index2
283
>>> matrix_index3
284
285
286
### Modify your code here
287
def matrix_index(i=None, j=None):
"""Indexing function which will retrive (i, j) entry of the input
288
289
290
matrix representation
291
292
Args:
i (int, optional): row index. Defaults to None. (0-index)
j (int, optional): column index. Defaults to None. (0-index)
293
294
295
296
Return:
297
List of List: a list of list representation of the indexed.
298
Return None if matrix or index is invalid
299
>>> matrix_index1()
[[1, 2], [2, 3]]
>>> matrix_index1(i=1) # row 1 (2nd row since 0 indexed)
[[2, 3]]
>>> matrix_index1(j=1) # col 1 (2nd row since 0 indexed)
[[2], [3]]
>>> matrix_index1(i=1, j=1)
[[3]]
>> print(matrix_index1(i=1, j=10))
300
301
302
303
304
305
306
307
308
309
None # invalid index
310
>> print(matrix_index3())
311
None # invalid matrix
EE EE EE
312
313](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6498d82d-8d6f-4397-b9f6-144bfabdced8%2Fc48bd93b-3f4f-4b43-9724-da0ed1f5f1c8%2F3r792oj_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 7 images









