fork(36) download
  1.  
  2. d = {'a': 3, 'b': 2, 'c': 3, 'd': 4}
  3.  
  4. from itertools import islice
  5.  
  6. def take(n, iterable):
  7. "Return first n items of the iterable as a list"
  8. return list(islice(iterable, n))
  9.  
  10. n_items = take(2, d.iteritems())
  11.  
  12. print n_items
Success #stdin #stdout 0.01s 6400KB
stdin
Standard input is empty
stdout
[('a', 3), ('c', 3)]