0

I am dealing with a huge dictionary FPKM, which has ~ 20 keys, but each key has a list of ~1 million values. I tried to use print(FPKM) to print everything, but it only prints the keys. What would be the problem? I also wanted to pickle out this FPKM object, but it turned out that only the keys were stored in the pickle file.


Dear all, I have to apologize that my case was not true. I did

print (sorted(FPKM))

it only printed keys if I do

fpkm=sorted(FPKM)

print (fpkm)

it worked. For pickle, it was the similar case, I used "sorted" instead of an pure object name.

I really appreciate all your answers.

huajun
  • 31
  • 5

3 Answers3

0

Practice using a small dictionary, and verify the large one behaves similarly:

#! /usr/bin/env python3

d = {'foo': [1, 2],
     'bar': [3, 4]}
print(type(d))
for k, v in d.items():
    print(k, v)
J_H
  • 17,926
  • 4
  • 24
  • 44
0

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

I don't think so.

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.

See How can I use pickle to save a dict?

import pickle
a = {'hello': 'world'}
with open('filename.pickle', 'wb') as f:
    pickle.dump(a, f, protocol=pickle.HIGHEST_PROTOCOL)

with open('filename.pickle', 'rb') as f:
    b = pickle.load(f)

print(a == b) # True
print(b) # The original dictionary persists {'hello': 'world'}
kgf3JfUtW
  • 13,702
  • 10
  • 57
  • 80
0

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

Lets say that these are the contents of FPKM:

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

If FPKM is a dict, then printing it should print the complete dictionary like so.

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

Make sure you aren't doing something like this instead.

for key in FPKM:
    print(key)

That would print:

one
two
three
Jebby
  • 1,845
  • 1
  • 12
  • 25