I am getting extra whitespace after the end of output because I've used end=' '
. How can I fix this?
for i in range(0,6):
for g,h in q[i].items():
print(h/len(q1[i]), end=" ") //here
print()
I am getting extra whitespace after the end of output because I've used end=' '
. How can I fix this?
for i in range(0,6):
for g,h in q[i].items():
print(h/len(q1[i]), end=" ") //here
print()
How about having just one print statement per line? You can use join
to put spaces between the values.
for i in range(6):
print(' '.join(str(h/len(q1[i])) for h in q[i].values()))
for i in range(0,6):
print(*[h/len(q1[i]) for g,h in q[i].items()])
print()
Using this answer, we can simply unpack the list to print everything without the inner for
loop.
Example:
>>> print(*[1,2,3])
1 2 3
Use str.join() to put spaces in between your items:
for i in range(0,6):
items = [str(h/len(q1[i])) for g,h in q[i].items()]
print(" ".join(items))