-1

I have tried adding (end = "") at the end of my print statements, but the values keep printing on a new line

for line in file:
    errorDict[line] = errorDict.get(line, 0) + 1

for i, n in errorDict.items():
    print (str(i) + str(":") + str(n))

It currently looks like this

5262200
:2
5DAA200
:1
531G200
:3
5700H3H
:1
5300A52
:2

I would like it to look like

5262200 : 2
5DAA200 : 1
531G200 : 3
5700H3H : 1
5300A52 : 2
jkim
  • 3
  • 1
  • 3

1 Answers1

2

Seems like the keys in your dict have a newline at the end. You can strip() them out before printing.

print (str(i).rstrip() + str(":") + str(n))

or before adding to the dict:

errorDict[line.strip()] = errorDict.get(line, 0) + 1
rdas
  • 20,604
  • 6
  • 33
  • 46