Last active
February 6, 2017 16:56
-
-
Save lotka/5b0a1ba2c453903d80850ece5c6d66a0 to your computer and use it in GitHub Desktop.
python functions
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
# Iterate through the pairs of a list | |
def pair_generator(iterable): | |
for i in xrange(0,len(iterable)-1,1): | |
yield iterable[i],iterable[i+1] | |
# print the structure of a dictionary | |
def dstruct(d,n=''): | |
if type(d) == dict: | |
for k in d: | |
print n + str(k) | |
dstruct(d[k],n=n+' ') | |
elif type(d) == list and len(d) > 0: | |
print n + '___list___' | |
dstruct(d[0],n=n+'| ') | |
return | |
else: | |
print n + str(type(d)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment