I\'m new to Python and having difficulty getting the output to print on one line.
This is pertaining to the online Python class Learning Python Essentials Lab 5.1.10.6
Your problem is that you are printing each number before the next, but you need to print each row before the next. As a simplified example:
dict1 = {
'0':('###','# #','# #','# #','###'),
'1':(' ##','###',' ##',' ##',' ##'),
'2':('###',' #','###','# ','###'),
'3':('###',' #','###',' #','###'),
'4':('# #','# #','###',' #',' #'),
'5':('###','# ','###',' #','###'),
'6':('###','# ','###','# #','###'),
'7':('###',' #',' #',' #',' #'),
'8':('###','# #','###','# #','###'),
'9':('###','# #','###',' #','###')
}
num = '0123456789'
for row in range(len(dict1['0'])):
print(' '.join(dict1[i][row] for i in num))
Output:
### ## ### ### # # ### ### ### ### ###
# # ### # # # # # # # # # # #
# # ## ### ### ### ### ### # ### ###
# # ## # # # # # # # # # #
### ## ### ### # ### ### # ### ###
If you don't want to use a list comprehension inside join
, you can unroll that like this:
for row in range(len(dict1['0'])):
line = []
for i in num:
line.append(dict1[i][row])
print(' '.join(line))