Consider the following dictionary, d:
d = {\'a\': 3, \'b\': 2, \'c\': 3, \'d\': 4, \'e\': 5}
I want to return the first N key:value pairs f
foo = {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6} iterator = iter(foo.items()) for i in range(3): print(next(iterator))
Basically, turn the view (dict_items) into an iterator, and then iterate it with next().