Home > database >  how do i compactly (without listing every index value) use a list when formatting a string
how do i compactly (without listing every index value) use a list when formatting a string

Time:10-10

values =[" ", " ", " ", " ", " ", " ", " ", " ", " ",
         " ", " ", " ", " ", " ", " ", " ", " ", " ",
         " ", " ", " ", " ", " ", " ", " ", " ", " ",
         " ", " ", " ", " ", " ", " ", " ", " ", " ",
         " ", " ", " ", " ", "9", " ", " ", " ", " ",
         " ", " ", " ", " ", " ", " ", " ", " ", " ",
         " ", " ", " ", " ", " ", " ", " ", " ", " ",
         " ", " ", " ", " ", " ", " ", " ", " ", " ",
         " ", " ", " ", " ", " ", " ", " ", " ", " ",]




outGrid = ("""
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
--------   --------   --------
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
--------   --------   --------
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
""" % (values))

Im making a sudoku game and cannot figure out a way to insert the values from the list into the grid with typing 'values' 81 times with all the indexes.

CodePudding user response:

You just need to convert values to a tuple:

outGrid = ("""
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
--------   --------   --------
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
--------   --------   --------
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
""" % tuple(values))

print(outGrid)

         |          |      
         |          |      
         |          |      
--------   --------   --------
         |          |      
         |     9    |      
         |          |      
--------   --------   --------
         |          |      
         |          |      
         |          |      

CodePudding user response:

: execute -55!:("Sudoku,-12:index=i.-ALL:55!:("var(values)";-.i=81=:a%outgrid%a:!!));..!.,

i would say use your letters to randomnize grid with this and use grid to transfer to saved location with listed ammount to deliver
55 = refresh
81 = grid
42 = transfer
98 = upload
45 = remove previous
56 = add new
  • Related