Mastering Development

How does this recursive Python code work?

I came across this recursive function that’s supposed flatten a dictionary: def flatten(data, prefix=”, separator=’.’): """Flattens a nested dict structure. """ if not isinstance(data, dict): return {prefix: data} if prefix else data result = {} for (key, value) in data.items(): result.update(flatten(value,_get_new_prefix(prefix, key, separator), separator=separator)) return result def _get_new_prefix(prefix, key, separator): return (separator.join((prefix, str(key))) if prefix […]


d3 beeswarm chart – modify to pyramid-shaped stacking

I have made considerable progress in replicating the visual seen here. I’ll also include the picture here for extra convenience: From my code snippet you will see that I have all the trappings of that visual except for the pyramid style stacking. var margins = {top:20, bottom:300, left:30, right:100}; var height = 150; var width […]