+ 1
Can you give me a sample python code to accept and print values of a matrix using lists.
5 Antworten
+ 2
OK for printing a list you can use this method:
https://code.sololearn.com/c3fiXhcCM0x9/?ref=app
Why use join? to get rid off square brackets and commas in printing output
Remember to use map with the list elements are not str type.
But we are talking about matrix.
So you can use a for-each
to iterate line by line and print with same method likes this:
https://code.sololearn.com/cDM5ajLc7KDo/?ref=app
0
What kind of matrix?
0
a matrix made-up of numbers
0
@shivaani i think HonFu is asking with is a 2d matrix or 3d.
0
The way I used so far in Python is one-dimensional lists that are interpreted two- or three-dimensionally by slicing.
Maybe I should quickly clarify that:
If you have a list like
rect = [0, 1, 2, 3,
4, 5, 6, 7]
and you want to read it vertically, you can write (example for first column)
print(rect[0::4])
using the slice's 'step' part.
https://code.sololearn.com/c36892iW8Srd/?ref=app
https://code.sololearn.com/cJPmTf5bW1la/?ref=app
https://code.sololearn.com/cOgBIKfp377h/?ref=app