Skip to content

Instantly share code, notes, and snippets.

def visit(node, parent, field_name, field_index):
node_item = handle_item(node, parent, field_name, field_index)
if node_item is None:
return
fields = {}
for field_name, field in ast.iter_fields(node):
fieldset = fields.setdefault(field_name, [])
if isinstance(field, list):
for i, item in enumerate(field):
data = [1,2,3,[4,5,6,[77,88]]]
def run_through(data):
for x in data:
if isinstance(x, list):
yield from run_through(x)
continue
yield x
it = run_through(data)
@dalejung
dalejung / hanoi.py
Created June 9, 2015 00:39
hanoi.py
def towers(num, frompeg, topeg, aux, final):
if num > 0:
towers(num-1, frompeg, aux, topeg, False)
if final:
print('final')
print("move disk %d from %s to %s" % (num, frompeg, topeg))
towers(num-1, aux, topeg, frompeg, final)
towers(5, 'A', 'B', 'C', True)
@dalejung
dalejung / empty.txt
Created May 21, 2015 04:09
nbx created gist
empty file created by nbx
@dalejung
dalejung / empty.txt
Created May 21, 2015 04:09
nbx created gist
empty file created by nbx
empty file created by nbx
@dalejung
dalejung / empty.txt
Created April 28, 2015 04:09
nbx created gist
empty file created by nbx
@dalejung
dalejung / empty.txt
Created April 19, 2015 04:09
nbx created gist
empty file created by nbx
@dalejung
dalejung / init object.ipynb
Created December 29, 2014 17:21
init object.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dalejung
dalejung / init object.ipynb
Last active August 29, 2015 14:12
init object.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.