You’re welcome and it’s okay.
Here’s a brief rundown just to show my thought process and to help understand what each lines purpose is for.
First I tried just
keyboard1 = [("\033[47m", "Q"),("\033[47m", "W")]
print(keyboard1)
which outputs [('\x1b[47m', 'Q'), ('\x1b[47m', 'W')]
I tried using eval()
, print(eval(keyboard1))
to interpret “\033[47m” as code instead of as a string but got the error
print(eval(keyboard1))
TypeError: eval() arg 1 must be a string, bytes or code object
So then I realized we needed to use a for loop
for item in keyboard1:
print(item)
this outputs
('\x1b[47m', 'Q')
('\x1b[47m', 'W')
So then I realized we needed another loop for each tuple, ('\x1b[47m', 'Q')
and ('\x1b[47m', 'W')
for item in keyboard1:
for thing in item:
print(thing)
This itself will work, it outputs :
So the rest of the code remaining now, is just to eliminate the unncessary spaces/lines where it’s printing “\033[47m” on the line, but we as the user don’t see anything.
for item in keyboard1:
for thing in item:
if thing == "\033[47m":
print(thing, end = "")
else:
print(thing)
I hope this makes the point of everything understandable.
If you’d rather have the letters output horizontally on one line like :
instead of vertically, the code can be condensed down to
for item in keyboard1:
for thing in item:
print(thing, end ="")