开发者

Appending a Counter() list to a pygtk treestore (Python)

开发者 https://www.devze.com 2023-04-06 19:12 出处:网络
I\'m currently attempting to append a sorted list of items to a pygtk treestore. The list is a count of the times the number occurs in the original list, eg. 2 lots of 24

I'm currently attempting to append a sorted list of items to a pygtk treestore. The list is a count of the times the number occurs in the original list, eg. 2 lots of 24

Generating the list

from collections import Counter
c = Counter(aSeries)
l = c.items()
l.sort(key = lambda item: item[0])
print l

Example of list printed

[(u'1', 23), (u'2', 24), (u'3', 23), (u'4', 17), (u'5', 25), (u'6', 23), (u'7', 22)]

Attempting to append

self.treestore.append(path, [l])

Image of list appended: http://i.stack.imgur.com/f3BGU.png

I would like the list to be appended like so

* 1: 23
* 2: 24
* 3: 23
* 4: 17
* 5: 25

How can i modify the way the list is counted or printed so that it will play n开发者_如何学JAVAicely with the syntax that treestore.append requires ?


This might depend a bit on your model, but how about something like this (i.e. append every single element of the list seperately to the treestore, which I assume to have only one column based on your picture):

l = c.items()
…
for (char, count) in l:
    treestore.append(parent, ("%d: %s" % (count, char),))
0

精彩评论

暂无评论...
验证码 换一张
取 消