I've customized flatten to allow for a two custom delimiters. I needed to be able to create post variables for a PHP api and your flatten function was the simplest thing to customize.
def flatten(o, left='.', right=''):
left = '%s' % left
right = '%s' % right
stack = [(wrap(o).iteritems(), None)]
while stack:
items_iter, parent_key = stack[-1]
for (key, value) in items_iter:
if parent_key is None:
full_key = key
else:
full_key = left.join([parent_key, '%s%s' % (key, right)] )
if value is not unwrap(value):
stack.append((iter(value.items()), full_key))
break
yield full_key, value
else:
stack.pop()
I've customized flatten to allow for a two custom delimiters. I needed to be able to create post variables for a PHP api and your flatten function was the simplest thing to customize.