Python Forum

Full Version: Can I delete single quotes in string matrix display
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all ! I should like to have a pretty display of the string matrix. Is it possible ??

print("MULTIPLICATION TABLE")


def pause():
    input("Press ENTER to continue")


M = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
print("New values in the matrix")
for i in range(len(M)):
    for j in range(len(M)):
        M[i][j] = i * j

print("Print the matrix 'M', beginning with a 0, display beginning by a 1"
for row in M[1:]:  # display beginning by item number 1, not number 0
    print(row[1:])  # display beginning by item number 1, not 0

pause()
print("This multiplication_table 'N' is a matrix beginning by a 1")
N = []
for x in range(1, 10):
    new_row = []
    for y in range(1, 10):
        new_row.append(x * y)
    N.append(new_row)
print(N)
pause()
print("Now a display of the same, row by row")
for row in N[0:]:  # begin by number 0
    print(row[0:])  # begin by number 0
pause()
print("The following 'P' is a matrix")
P = [[x * y for y in range(1, 10)] for x in range(1, 10)]
print(P)

for x in range(len(P)):
    print(P[x])
pause()
print("New 'P'  in a square")
for i in range(len(P)):
    for j in range(len(P)):
        if len(str(P[i][j])) == 1:
            P[i][j] = " " + str(P[i][j])
        else:
            P[i][j] = str(P[i][j])

for x in range(len(P)):
    print(P[x])


pause()
print("\nNow action between the 2 matrixes 'M', beginning with a 0, and 'N' with a 1 ")
print([M[row][col] * N[row][col] for row in range(5) for col in range(5)])
print("second action")
print([[M[row][col] * N[row][col] for row in range(5)] for col in range(5)])

exit()
>>> from pprint import pprint

>>> pprint(matrix)
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
Thank you. This is new useful information for me. Below my thread, there is a thread of 'sparkz_ alot': remove apostrophes in list
sparkz_alot which gives information to me too.