def transform_hits(hits):
packages = {}<EOL>for hit in hits:<EOL><INDENT>name = hit['<STR_LIT:name>']<EOL>summary = hit['<STR_LIT>']<EOL>version = hit['<STR_LIT:version>']<EOL>score = hit['<STR_LIT>']<EOL>if score is None:<EOL><INDENT>score = <NUM_LIT:0><EOL><DEDENT>if name not in packages.keys():<EOL><INDENT>packages[name] = {'<STR_LIT:name>': name, '<STR_LIT>': summary, '<STR_LIT>': [version], '<STR_LIT>': score}<EOL><DEDENT>else:<EOL><INDENT>packages[name]['<STR_LIT>'].append(version)<EOL>if version == highest_version(packages[name]['<STR_LIT>']):<EOL><INDENT>packages[name]['<STR_LIT>'] = summary<EOL>packages[name]['<STR_LIT>'] = score<EOL><DEDENT><DEDENT><DEDENT>package_list = sorted(packages.values(), key=lambda x: x['<STR_LIT>'], reverse=True)<EOL>return package_list<EOL>
The list from pypi is really a list of versions. We want a list of
packages with the list of versions stored inline. This converts the
list from pypi into one we can use.