#πŸ”’ help with printing a list with rows

234 messages Β· Page 1 of 1 (latest)

sweet grotto
#

in my tetris project the grid is stored as a list with 200 items that are either 0, 1 or 2 (empty tile, full tile and full tile in control of the player respectively) now what i need to do is print all the items in the list so that the result would be this:
<!. . . . . . . . . . !> 0
<!. . . . . . . . . . !> 10
...
<!. . . . . . . . . . !> 190

so on for 20 rows
the numbers on the side of the lines are the tenths of the tile indexes of said lines.
(". " if its 0 and "[]" if its 1 or 2)

the way i did this is:

tile_options = [". ", "[]"]
    for i in range(len(grid)):   
        m = i % 10    
        if grid[i] == 0:                
            tile_state = tile_options[0]    
        else:                               
            tile_state = tile_options[1]    
        if m == 0:          
            print("<!", tile_state,sep='', end='')  
        elif m == 9:        
            print(tile_state, "!>  ", i // 10*10,sep='')   
        else:               
            print(tile_state,sep='',end='')    

is there an easier/more optimal way to do this?

balmy loomBOT
#

@sweet grotto

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

main ingot
#

why so many comments

sweet grotto
#

so i dont forget

#

i forgot to remove them when pasting the code here

#

there i changed it

barren marten
#

it must be quite cumbersome to move things when it's stored in one big list instead of as a grid, or isn't it?

sweet grotto
#

not really the way i do this is i have a list of 4 indexes of the grid list called piece_tiles which is the location of the tiles that make the piece and every time i want to move it first i turn those items in grid to 0, then i run piece_tiles through the function for inputs which changes the indexes and then i activate the new indexes in the grid list

#

basically:
turn tiles off
change the coordinates of the tiles
turn new tiles on
print grid

barren marten
sweet grotto
#

how so?

barren marten
# sweet grotto how so?

can you give me example data for the content of grid so that i have some data to work with?

sweet grotto
#

grid = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0....]
its either 0, 1 or 2 and theres 200 items

barren marten
#

yeah, i was hoping to get a full state to experiment with

sweet grotto
#

the full list?

barren marten
#

yeah, where there is a bit of tiles in the data in sane places

#

just because grid = [0 for _ in range(200)] didn't produce much "real" data to work with, it's kind of uniform

#

i guess i could even have used grid = [0] * 200

sweet grotto
#

like this?

grid = [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, 2, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 2, 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, 1, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 
1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 

0 is empty
1 is a normal full tile
2 is a full tile thats connected to the piece_tiles list which is constantly changing with player inputs

barren marten
#

!e - maybe not the most readable code, but still

WIDTH = 10
tiles = [". ", "[]", "[]"]

grid = [
    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, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 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, 1, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
    1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 
    1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
]

for i in range(0, len(grid), WIDTH):
    line = "".join([tiles[x] for x in grid[i:i+WIDTH]])
    print(f"<!{line}!>")
balmy loomBOT
# barren marten !e - maybe not the most readable code, but still ```py WIDTH = 10 tiles = [". ",...

:white_check_mark: Your 3.13 eval job has completed with return code 0.

001 | <!. . . . . . . . . . !>
002 | <!. . . . . . . . . . !>
003 | <!. . . . . . . . . . !>
004 | <!. . . . . . . . . . !>
005 | <!. . . . . . . . . . !>
006 | <!. . . . . . . . . . !>
007 | <!. . . . . . . . . . !>
008 | <!. . . . . []. . . . !>
009 | <!. . . . . []. . . . !>
010 | <!. . . . . []. . . . !>
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/4OTYWCTNTLROBHX3GUJEMCFFY4

barren marten
#

@sweet grotto you'll have to follow the link there to see the full output πŸ‘†

sweet grotto
#

can you explain this part: ```py
for i in range(0, len(grid), WIDTH):
line = "".join([tiles[x] for x in grid[i:i+WIDTH]])
print(f"<!{line}!>")

main ingot
sweet grotto
#

and the print line too

barren marten
# sweet grotto and the print line too

the print line is easy it's just what is called f-strings (means "format" strings, they start with an f just in-front of the quotes at the start of the string)
it uses something called string interpolation to substitute the content within {} in the string for what ever the code in there produces, in our case it's just the content of the variable that i put in there

#

i could have put all the code that produces line there, but i think it will be even harder to read the code if i do, so i opted to put it into a variable first to keep it separate

#

the way i use range here is to start from 0 and go until len(grid) (which is 199) but stepping the counter with the WIDTH of the printed grid which is 10, so range() will produce 0, 10, 20, 30... and so on until 190

barren marten
#

that is put into the i variable at each iteration of the loop

sweet grotto
#

oh right

barren marten
#

then i use slicing to get me a part of the grid that we are interested in currently for that loop iteration, with grid[i:i+10] which is the same as saying grid[0:10] (which gives us elements 0 through 9 since the first number in a range is inclusive but the last number is exclusive) for the first iteration and grid[10:20] (giving us elements 10 through 19) for the second iteration and so on

sweet grotto
#

oh so thats what that was

barren marten
#

then i use a list comprehension to iterate through that slice that we are currently working with for that line and using the value stored in each element in that slice to get me the content from the tiles list depending on the value of that element, so instead of using the number stored we use it to get the correct string out of the tiles list

#

and then we just join it all together as one string and put it in the line variable

#

as we don't want anything in-between each element we use the empty string "" as the delimiter between each element when we join them together as a string

#

@sweet grotto i don't know if you know list comprehensions yet

sweet grotto
#

no i dont

#

hold on lemme look it up

barren marten
#

it's a way to loop through a iterable and produce a list based on the iterable that you were looping through

sweet grotto
#

so its basically this?

for x in grid[i:i+10]:
    line += tiles[x]
#

but in 1 line

barren marten
sweet grotto
#
for x in grid[i:i+10]:
    line.append(tiles[x])
```?
barren marten
sweet grotto
barren marten
#

if we skip the .join() for now it's the

line = [tiles[x] for x in grid[i:i+WIDTH]]
```part that would be equivalent to
```py
line = []
for x in grid[i:i+10]:
    line.append(tiles[x])
```all packed in to one line
sweet grotto
#

i see
so its a way to compress the code

barren marten
# sweet grotto also is using a list better then a string?

yes, because strings are internally immutable in python, so you would need to construct a new string each time you append a character to it and then replace the content of the variable holding the string with the new string, it's kind of expensive in terms of resources

barren marten
sweet grotto
sweet grotto
barren marten
#

i think you misunderstand, concatenations of strings in python is "expensive" as it takes two strings and produce a new string each time

sweet grotto
#

because im replacing it with itself with an addition

barren marten
#

and the variable that points to that string gets updated to point to the new string instead

#

the + sign that looks like an addition is just syntactic sugar for string concatenation when it's between two strings, but yeah

sweet grotto
#

alright

barren marten
#

so producing new strings copying all the content of the previous string isn't the best way to produce strings in a loop

#

it's often better to use a list that you append to and then you just join the elements together into a string when you are done with everything that should produce one string

#

now let's add the .join() to the mix

line = "".join([tiles[x] for x in grid[i:i+WIDTH]])
```is roughly equal to
```py
tmp = []
for x in grid[i:i+10]:
    tmp.append(tiles[x])
line = join(tmp)
```but all packed in to one line and more efficient too (as we don't need the `tmp` list)
#

we can get even more fancy by changing the list comprehension to a generator comprehension (which usually use normal parentheses () instead) by simplifying the code and just removing the [] square brackets around the comprehension
but here we are already in an iterator context which the .join() provides

#
line = "".join(tiles[x] for x in grid[i:i+WIDTH])
#

there, better

#

a little bit more advanced concept but shorter syntax and is absolutely fine in this instance

#

i didn't know if you knew about generator functions and yield

sweet grotto
sweet grotto
barren marten
#

you usually return the result of a function all at once

sweet grotto
#

yes, sometimes into multiple variable too

barren marten
#

but you can instead yield one result at a time from a function until there is nothing more to yield

barren marten
sweet grotto
#

oh so one adds the results and releases them at once and the other releases them 1 by one

barren marten
#

exactly, this is what range() does for example

#

and map() too

sweet grotto
sweet grotto
barren marten
#

they produce values while you fetch them one by one

sweet grotto
barren marten
#

you can unpack collections such as lists, tuples and sets for example

#

into more then one variable at a time

#

but, the number of elements or items in the data that you unpack must match exactly the number of variables that you are trying to unpack them into or else the code will raise an exception

sweet grotto
#

obviously
like with executing functions with variables

#

and 1 last thing just because im curious,
instead of .join() i can print it like this too right?

print("<!", *line, "!>", sep="")
barren marten
#

yeah, that would work, but you would have to keep the parentheses from .join() when assigning to line

#

!e - we can even do it within the print to produce a monstrosity like this one

WIDTH = 10
tiles = [". ", "[]", "[]"]

grid = [
    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, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 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, 1, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
    1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 
    1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
]

for i in range(0, len(grid), WIDTH):
    print("<!", *(tiles[x] for x in grid[i:i+WIDTH]), "!>", sep="")
balmy loomBOT
# barren marten !e - we can even do it within the print to produce a monstrosity like this one `...

:white_check_mark: Your 3.13 eval job has completed with return code 0.

001 | <!. . . . . . . . . . 
002 | <!. . . . . . . . . . 
003 | <!. . . . . . . . . . 
004 | <!. . . . . . . . . . 
005 | <!. . . . . . . . . . 
006 | <!. . . . . . . . . . 
007 | <!. . . . . . . . . . 
008 | <!. . . . . []. . . . 
009 | <!. . . . . []. . . . 
010 | <!. . . . . []. . . . 
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/V4HHTKJH7G4LB7FIF5UE4JQNSI

barren marten
#

kind of an abomination i would say to make it into one line like that

barren marten
#

the * there is an explicit unpacking, same as in your *line

sweet grotto
#

yea

#

its kinda fun for me to think of alternative ways i can do things in python

#

oh and since im overwriting existing lines il also add "\033[0K" inside the print

barren marten
#

depends on how you are doing things

main ingot
barren marten
#

could just skip the outer for loop too, but no

main ingot
barren marten
main ingot
#

is there any particular reason this grid is a 1d list btw

barren marten
main ingot
#

ye ik which is why im asking again

#

did we ever figure that one out

#

or nah

barren marten
#

i think it has to do with it being a simpler data structure

main ingot
#

so for a "simpler" data structure u make eldritch horrors of algorithms

#

i approve

main ingot
#

is this a telegram bot and thats reason or

barren marten
#

don't think so as OP is using control sequences to control the terminal

main ingot
#

idk what it is about this but it screams telegram bot to me

barren marten
#

really?
i would never have thought so as they are controlling a terminal like that, don't think you can do that on telegram

sweet grotto
#

sorry i dissapeared i had to so something urgent

sweet grotto
main ingot
#

this a flattened 2d grid

#

there is nothing 2d about it

main ingot
#

if we just make it a 2d list then everything much easier

sweet grotto
#

is there a simpler way to do it?

main ingot
#

but im biased towards the eldritch horror solutions

main ingot
sweet grotto
#

yea that is kinda funny

sweet grotto
main ingot
#

2d grid means grid is a list of lists

#

each list inside grid is a row

sweet grotto
#

oh no

#

that was the first thing i tried to do

main ingot
#
grid = [
    [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, 2, 0, 0, 0, 0], 
    [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], 
    [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], 
    [0, 0, 0, 0, 0, 2, 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, 1, 0, 0, 0, 0, 0], 
    [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 
    [1, 0, 0, 0, 1, 0, 0, 1, 1, 0], 
    [1, 1, 1, 1, 1, 0, 0, 0, 1, 0],
]
#

yes i did that by hand

sweet grotto
#

wow

#

anyhway isnt this more complicated

main ingot
#

not at all

#

it looks more complicated but it makes life a lot easier

sweet grotto
#

but now i need to go through 2 lists to get to an item

main ingot
#

u dont want "simpler" data structures, hell my data structure for this silly project is an abberation, but it simplifies my algorithm donw like 7 notches so i stick to it

#

u want simpler algorithms since they the complicated things

main ingot
#

using said position u can get any item in grid this way

#

!e

grid = [
    [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, 2, 0, 0, 0, 0], 
    [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], 
    [0, 0, 0, 0, 0, 2, 0, 0, 0, 0], 
    [0, 0, 0, 0, 0, 2, 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, 1, 0, 0, 0, 0, 0], 
    [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 
    [1, 0, 0, 0, 1, 0, 0, 1, 1, 0], 
    [1, 1, 1, 1, 1, 0, 0, 0, 1, 0],
]

position = 4, 5

x, y = position

print(grid[x][y])
balmy loomBOT
main ingot
#

so our character which is at 4,5 is stepping on watever 0 is

#

simple as that

sweet grotto
#

isnt it easier to just store it as a line and going to the 55th position directly

main ingot
#

u adjusting every single position update in favor of flattening this grid

#

if u want to go down ? then position -= WIDTH * y_velocity

#

instead of just position -= y_velocity

#

and in hindsight it isnt even obvious why width matters for going down

#

and reason it matters is cause thats how u index a flattened 2d list

#

even tho velocity multiplier should be like running speed or watever insteadpithink

sweet grotto
#

but then when i wanna store a piece instead of it being 4 numbers it needs to be 8

sweet grotto
#

yes

main ingot
#

then what u want to do is not store positions in piece but store piece directly in grid

sweet grotto
#

i said so in the post description

main ingot
#

thats a piece

sweet grotto
#

ik

main ingot
sweet grotto
#

thats alright

sweet grotto
#

and the reason its either 0, 1 or 2 rather then a boolean is with collision between pieces but thats another matter

main ingot
#

do u want to be able to rotate pieces in future ?

sweet grotto
#

yes

#

ill just have an equation that gives me the new tile indexes based on the previous

#

i didnt get there yet

#

do u have something else in mind?

main ingot
#

lets say for the 2 piece its the very top by default

sweet grotto
#

yea top left of the piece

main ingot
#

then we code that it goes down 3 (stupid matrices and vectors)

#

so when we rotate it we use its location as the pivot

main ingot
#

the result is new locations

#

@barren marten got a simpler way ?

#

my brain can only think of it going this way pithink

barren marten
main ingot
#

my brain is trying hard to not use classes but also having a hard time not going down lin alg

barren marten
#

pivoting them 90 degrees should be easy enough by just flipping the x and the y between reading and writing one element i think

#

as long as the whole matrix is just that piece

sweet grotto
#

I can do it by rather then just 4 set tiles as 1 starting tile and the other 3 relative to it (for example for the line piece as [x, x + 10, x + 20, x + 30])
Effectively drawing it from said point.
And do that for each rotation so that I only need to move the starting point and getting the tile indexes from the relevant list

#

Problem is the many exceptions such as walls and other pieces

main ingot
sweet grotto
#

thats not it

#

for example in this case
<!. . . . . . . . . . !>
<!. . . . . . . . []. !>
<!. . . . . . . . []. !>
<!. . . . . . . . []. !>
<!. . . . . . . . []. !>
when the piece will try to rotate some of it will end up outside the grid and that will not allow it to rotate but as a player you see that theres room to rotate it to so itd be annoying

#

<!. . . . . . . . . . !>
<!. . . . . . . . . . !>
<!. . . . . . . . . . !>
<!. . . . . . . . . . !>
<!. . . . . . . . []. !>
since it will try to make the piece from this tile

barren marten
#

you would have to shift its position so that it doesn't go out of bounds

sweet grotto
#

Thats fine in this case but there's still more cases with more complex situations

barren marten
#

it depends, i don't know all the internal rules of movement when flipping a piece in tetris, for the two walls on either side it's kind of simple
but the question is: which position within a piece is used for rotation of the different shapes?

sweet grotto
#

Top left of the piece

barren marten
#

i don't think that holds true for the original popularized version of the game though

#

i think it's closer to the middle of the piece

sweet grotto
#

i can still make it rotate around the center of the piece while the starting point is the top right

barren marten
#

of course

sweet grotto
#

and a complex situation can be this:

<!. . . . . . . . . . !>
<![][][][]##. . . . . !>
<![][][]. ####[][][][]!>
<![][][][]##[][][][][]!>
<![][][][][][][][][][]!>```
#

"##" is the piece

barren marten
#

for this piece it's quite obvious what the rotation center is

#

it's the other shapes that are a little bit more tricky what they should be

main ingot
#

This reminds me of tetris os

sweet grotto
#

how about this one

main ingot
#

that one shouldnt be able to rotate tbh but if we ignoring physical collision during rotation then only possible rotation is it going to right and top bit becoming far left

barren marten
#

i think that one should not be allowed to rotate at that position due to collisions and how it wouldn't shift the position of the piece like the walls allows for

sweet grotto
#

but wouldnt players expect the logical rotation to be this

<!. . . []. . . . . . !>
<!. . . []. . []. . . !>
<![][]########[][]. . !>
<![][][][]. . [][][][]!>
<![][][][]. [][][][][]!>
main ingot
#

that feels straight like it violates 17 laws of physics to me

barren marten
#

they would have had to been at least one position to the left to be able to rotate into that position as far as i'm concerned

sweet grotto
#

yk what ill try to do it normally and send to my friends to playtest

main ingot
#

always best

sweet grotto
#

honestly i can pull the "its not that bad just dont get into these situations" move

main ingot
#

aka troll game dev move

#

so many funny games like that been game recently

sweet grotto
#

or turn it into an easter egg of some sort

#

such as if you get into that specific position i delete system32

#

a "haha funny"

barren marten
#

or "melt" the piece to make it fit whatever shape that number of blocks could fill, like a small cheat

barren marten
#

!e - oh no @main ingot look what you made me do

WIDTH = 10
tiles = [". ", "[]", "[]"]

grid = [
    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, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 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, 1, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
    1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 
    1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
]

print(*("".join(("<!",*(tiles[x] for x in grid[i:i+WIDTH]),"!>")) for i in range(0,len(grid),WIDTH)),sep="\n")
balmy loomBOT
# barren marten !e - oh no <@275449332960854016> look what you made me do ```py WIDTH = 10 tiles...

:white_check_mark: Your 3.13 eval job has completed with return code 0.

001 | <!. . . . . . . . . . !>
002 | <!. . . . . . . . . . !>
003 | <!. . . . . . . . . . !>
004 | <!. . . . . . . . . . !>
005 | <!. . . . . . . . . . !>
006 | <!. . . . . . . . . . !>
007 | <!. . . . . . . . . . !>
008 | <!. . . . . []. . . . !>
009 | <!. . . . . []. . . . !>
010 | <!. . . . . []. . . . !>
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/REDJN75A7BOGG4QTY4UKGPUAVM

main ingot
#

can u map(tiles.__getitem__, grid[i:i+WIDTH]), is that gonna work the way i hope it does . . . @barren marten

barren marten
#

yeah, that works too

#

!e - oh no @main ingot look what you made me do

WIDTH = 10
tiles = [". ", "[]", "[]"]

grid = [
    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, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 2, 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, 1, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
    1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 
    1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
]

print(*("".join(("<!",*map(tiles.__getitem__, grid[i:i+WIDTH]),"!>")) for i in range(0,len(grid),WIDTH)),sep="\n")
balmy loomBOT
# barren marten !e - oh no <@275449332960854016> look what you made me do ```py WIDTH = 10 tiles...

:white_check_mark: Your 3.13 eval job has completed with return code 0.

001 | <!. . . . . . . . . . !>
002 | <!. . . . . . . . . . !>
003 | <!. . . . . . . . . . !>
004 | <!. . . . . . . . . . !>
005 | <!. . . . . . . . . . !>
006 | <!. . . . . . . . . . !>
007 | <!. . . . . . . . . . !>
008 | <!. . . . . []. . . . !>
009 | <!. . . . . []. . . . !>
010 | <!. . . . . []. . . . !>
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/WQ2SU7EYWUA2SLNYR6ZXW7AAFI

barren marten
#

πŸ‘

main ingot
barren marten
balmy loomBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.