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] = {<EOL>'<STR_LIT:name>': name,<EOL>'<STR_LIT>': summary,<EOL>'<STR_LIT>': [version],<EOL>'<STR_LIT>': score,<EOL>}<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(<EOL>packages.values(),<EOL>key=lambda x: x['<STR_LIT>'],<EOL>reverse=True,<EOL>)<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.