https://gist.github.com/pkucmus/8cca7a2cfcb351b257c0#file-dict2-py-L22-L29