作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在考虑将字典的内容打印到表格中,字典的定义如下:
d = {"date": tuple(date),"open":tuple(open),"close":tuple(close),"min":tuple(min),"max":tuple(max),"gain":tuple(gain),"loss":tuple(loss),"avg_gain":tuple(avg_gain),"avg_loss":tuple(avg_loss)}
我想遍历它以在 shell 中逐行打印,第一行将包含键,接下来的行是元组(日期)、元组(打开)等的内容 ...
最佳答案
如何将键连接到元组的前面,然后使用 zip(*) 转置结果
>>> d={"A":(1.0,2.0,3.0), "B":(4.0,5.0,6.0), "C":(7.0,8.0,9.0)}
>>> for row in zip(*([k]+map(str,v) for k,v in sorted(d.items()))):
... print "\t".join(row)
...
A B C
1.0 4.0 7.0
2.0 5.0 8.0
3.0 6.0 9.0
关于python - 遍历字典并在表中返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4426025/
我是一名优秀的程序员,十分优秀!