Created
May 25, 2018 18:11
-
-
Save ctufts/3435bd48a7dbb9c71d18d637e0df5ca9 to your computer and use it in GitHub Desktop.
Helpful Python Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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