How do I print these dictionary elements next to each other?

86 Views Asked by At

While printing this dictionary that uses ascii art for the values, I realised that it will always print the values on top of each other rather than next to each other. I'm not sure how to make them line up next to each other.

def ABL():
  ABLs = {
   "B1": '''
    ---
   | 1 |
    ---
   ''',
   "B2": '''
    ---
   | 2 |
    ---
   ''',
   "B3": '''
    ---
   | 3 |
    ---
   ''',
   "B4": '''
    ---
   | 4 |
    ---
   '''
 }
  print(*ABLs.values())

This prints each value directly below the next one, and I am not sure how to make them sit in a row. Please help!

I tried changing the positioning of the apostrophes, but it resulted in the inability to use the ascii art.

1

There are 1 best solutions below

0
quamrana On

Yes, you can use a combination of splitting the lines and zipping them back together:

def ABL():
  ABLs = {
   "B1": '''
    --- 
   | 1 |
    --- 
   ''',
   "B2": '''
    --- 
   | 2 |
    --- 
   ''',
   "B3": '''
    --- 
   | 3 |
    --- 
   ''',
   "B4": '''
    --- 
   | 4 |
    --- 
   '''
 }
  ART = [a.split('\n') for a in ABLs.values()]
  for lines in zip(*ART):
      print(*lines)

ABL()

Note that I had to add an extra space on the end of each of the lines:

---