Skip to content

Instantly share code, notes, and snippets.

@lotka
Last active February 6, 2017 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotka/5b0a1ba2c453903d80850ece5c6d66a0 to your computer and use it in GitHub Desktop.
Save lotka/5b0a1ba2c453903d80850ece5c6d66a0 to your computer and use it in GitHub Desktop.
python functions
# 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