Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Created March 24, 2015 06:43
Show Gist options
  • Select an option

  • Save lanfon72/e6ea404ff73f2ea7def5 to your computer and use it in GitHub Desktop.

Select an option

Save lanfon72/e6ea404ff73f2ea7def5 to your computer and use it in GitHub Desktop.
import sys
def print_lol(the_list,indent=False,level=0,fh=sys.stdout):
for each_item in the_list:
if isinstance(each_item,list):
print_lol(each_item,indent,level+1,fh)
else:
if indent:
for tab_stop in range(level):
print("\t",end='',file=fh)
print(each_item,file=fh)
if __name__ == "__main__":
test = ["A","B",["C","D",["E"]]]
print_lol(test, False, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment