Python port Underscore.js