preresult is an OrderedDict().
I want to save the first 100 elements in it. Or keep preresult but delete everything other than the first 100 elements.
The structure is like this
stats = {'a': {'email1':4, 'email2':3},
'the': {'email1':2, 'email3':4},
'or': {'email1':2, 'email3':1}}
Will islice work for it? Mine tells itertool.islice does not have items
Here’s a simple solution using
itertools:This returns only keys. If you want items, use
iteritems(or justitemsin Python 3):