這是你想要的嗎?
from collections import Counter
stuff = Counter({'\n': 9, '#': 8, '&': 7, '3': 6, '*': 4, '%': 4, '1': 3, '8': 3, '0': 3, ')': 2, '+': 2, '4': 2, '7': 2, '2': 2, '-': 2, '/': 1, ',': 1, '$': 1, '6': 1, '5': 1, '!': 1, '.': 1, ':': 1, '"': 1, "'": 1, '9': 1})
stuff = dict(stuff)
line = []
for i,kv in enumerate(stuff.iteritems(), start=1):
line.append("%s : %d" % kv)
if i % 4 == 0:
print line
line = []
if line: print line
產地:
['\n : 9', '! : 1', '# : 8', '" : 1']
['% : 4', '$ : 1', "' : 1", '& : 7']
[') : 2', '+ : 2', '* : 4', '- : 2']
[', : 1', '/ : 1', '. : 1', '1 : 3']
['0 : 3', '3 : 6', '2 : 2', '5 : 1']
['4 : 2', '7 : 2', '6 : 1', '9 : 1']
['8 : 3', ': : 1']
爲了獲得更多的條目,每行,改變i % 4
線。
你可以使用美麗的打印機:https://docs.python.org/2/library/pprint.html – Scironic 2015-03-31 11:08:51
首先,你似乎已經使用過'collections.Counter',其次,你能解釋一下你的意思嗎?並且更容易理解*,你能舉個例子嗎? – Kasramvd 2015-03-31 11:08:57
應用程序的用戶需要能夠非常理解手錶正在顯示,所以可能是這樣的: – willstaff 2015-03-31 11:10:58