How to do matrix input in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to do matrix input in python

Using any way

20th Jun 2019, 4:34 PM
Karthik Devillers
Karthik Devillers - avatar
2 Answers
+ 4
>>> lst = list(range(-10,21,5)) >>> lst [-10, -5, 0, 5, 10, 15, 20] fills a list lst with numbres from -10 up to 20 with numbers in step of 5 >>> lst.append('a, b, c') >>> lst [-10, -5, 0, 5, 10, 15, 20, 'a, b, c'] appends 3 new elements >>> lst.insert(2, 'XX') >>> lst [-10, -5, 'XX', 0, 5, 10, 15, 20, 'a, b, c'] inserts a new element at index 2 >>> lst[4] = 55 >>> lst [-10, -5, 'XX', 0, 55, 10, 15, 20, 'a, b, c'] list element with index 4 will be peplaced with 55 >>> lst.remove(20) >>> lst [-10, -5, 'XX', 0, 55, 10, 15, 'a, b, c'] list element "20" will be removed
20th Jun 2019, 6:35 PM
Lothar
Lothar - avatar
0
rows of 3 n = [int(i) for i in input().split()] matrix = [n[i:i+3] for i in range(0,len(n),3)]
20th Jun 2019, 4:52 PM
Choe
Choe - avatar