for v in range (1, 10):
    for h in range (1, 10):
        print (f "{(v * h): 3d}", end = "")
    print ("")

I'd like to make this two-dimensional list into a two-dimensional list and make the result read from the list the same as when executing the above program, but I'm worried about this for two hours.

I managed to make a two-dimensional list, but can you teach me how to call it from the creation program below? Thank you.

kuku = []
for v in range (1, 10):
    list_kuku = []
    for h in range (1, 10):
        list_kuku.append (v * h)
    kuku.append (list_kuku)
print (kuku)
  • Answer # 1


    import sys
    import numpy as np
    kuku = [[v * h for h in range (1, 10)] for v in range (1, 10)]
    print ("")
    np.savetxt (sys.stdout.buffer, kuku, delimiter = "", fmt = "% 3d")

    Execution example

    Reference information

    Python matrix output 2D array

    Standard output with numpy.savetxt

  • Answer # 2

    After creating the list, you can loop around again and output it in the same way.

    for row in kuku:
        for elem in row:
            print (f "{elem: 3d}", end = "")
        print ("") # just print () is better

Related articles