Skip to content

Instantly share code, notes, and snippets.

@ctufts
Created May 25, 2018 18:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ctufts/3435bd48a7dbb9c71d18d637e0df5ca9 to your computer and use it in GitHub Desktop.
Helpful Python Snippets
# select n items from a dict
from itertools import islice
def take(n, iterable):
"Return first n items of the iterable as a list"
return list(islice(iterable, n))
n = 5
for k,v in take(n, dictionary.items()):
print(k,v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment