在python中存储或打印一个巨大的字典

2024-06-16 12:41:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在处理一个巨大的字典FPKM,它有大约20个键,但是每个键都有大约100万个值的列表。我试着用print(FPKM)打印所有东西,但它只打印钥匙。会有什么问题? 我还想提取这个FPKM对象,但结果发现pickle文件中只存储了密钥。在


亲爱的各位,我不得不道歉,我的案子不是真的。是的

打印(已排序(FPKM))

它只打印钥匙 如果我这么做

fpkm=已排序(fpkm)

打印(fpkm)

成功了。 对于pickle,情况也是类似的,我使用“sorted”而不是纯对象名。在

我真的很感激你的回答。在


Tags: 文件对象列表字典排序密钥情况pickle
3条回答

I tried to use print(FPKM) to print everything, but it only prints the keys.

我不这么认为。在

a = {'hello': 'world'}
print(a) # The entire dictionary is printed {'hello': 'world'}

I also wanted to pickle out this FPKM object, but it turned out that only the keys were stored in the pickle file.

How can I use pickle to save a dict?

^{pr2}$

练习使用小字典,并验证大字典的行为类似:

#! /usr/bin/env python3

d = {'foo': [1, 2],
     'bar': [3, 4]}
print(type(d))
for k, v in d.items():
    print(k, v)

I tried to use print(FPKM) to print everything, but it only prints the keys.

假设以下是FPKM的内容:

FPKM = {'one': 1,
        'two': 2,
        'three': 3
}

如果FPKM是dict,那么打印它应该像这样打印完整的字典。在

^{pr2}$

确保你不是在做这样的事情。在

for key in FPKM:
    print(key)

这将打印:

one
two
three

相关问题 更多 >