将 Counter() 列表附加到 pygtk 树存储 (Python)
我目前正在尝试将排序后的项目列表附加到 pygtk 树存储中。 该列表是该数字在原始列表中出现的次数的计数,例如。 2 批,每批 24
生成列表
from collections import Counter
c = Counter(aSeries)
l = c.items()
l.sort(key = lambda item: item[0])
print l
打印列表示例
[(u'1', 23), (u'2', 24), (u'3', 23), (u'4', 17), (u'5', 25), (u'6', 23), (u'7', 22)]
尝试附加
self.treestore.append(path, [l])
附加列表图像:https://i.sstatic.net/f3BGU.png
我希望像这样附加列表
* 1: 23
* 2: 24
* 3: 23
* 4: 17
* 5: 25
我如何修改列表的方式被计数或打印它能很好地适应 treestore.append 所需的语法吗?
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: https://i.sstatic.net/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 nicely with the syntax that treestore.append requires ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能有点取决于您的模型,但是像这样的东西怎么样(即,将列表中的每个元素单独附加到树存储中,根据您的图片,我假设树存储中只有一列):
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):