4 ms·
langs = list() f = open('langs.txt', 'r') content = f.readline() while content != "": line = content.strip() if line != "": temp = {} parts = line.split(
by chrisallick 15y ago
langs = list()
f = open('langs.txt', 'r')
content = f.readline()
while content != "":
line = content.strip()
if line != "":
temp = {}
parts = line.split(" ")
if "points" not in parts:
temp['title'] = parts[0]
nextline = f.readline().strip()
parts = nextline.split(" ")
temp['score'] = parts[0]
langs.append( temp )
content = f.readline()
newlist = sorted(langs, key=lambda k: int(k['score']))
print newlist
"""
[{'score': '6', 'title': 'Cobol'}, {'score': '6', 'title': 'Rexx'}, {'score': '7', 'title': 'Fortran'}, {'score': '8', 'title': 'Ada'}, {'score': '8', 'title': 'Pascal'}, {'score': '9', 'title': 'Groovy'}, {'score': '12', 'title': 'ColdFusion'}, {'score': '14', 'title': 'Delphi'}, {'score': '14', 'title': 'Tcl'}, {'score': '16', 'title': 'Shell'}, {'score': '18', 'title': 'Forth'}, {'score': '20', 'title': 'D'}, {'score': '23', 'title': 'Visual'}, {'score': '24', 'title': 'Smalltalk'}, {'score': '29', 'title': 'SQL'}, {'score': '30', 'title': 'Assembly'}, {'score': '31', 'title': 'OCaml'}, {'score': '32', 'title': 'Actionscript'}, {'score': '51', 'title': 'Lua'}, {'score': '57', 'title': 'Erlang'}, {'score': '74', 'title': 'Scheme'}, {'score': '92', 'title': 'Scala'}, {'score': '100', 'title': 'Other'}, {'score': '120', 'title': 'Perl'}, {'score': '123', 'title': 'Objective'}, {'score': '125', 'title': 'Lisp'}, {'score': '163', 'title': 'CoffeeScript'}, {'score': '187', 'title': 'Clojure'}, {'score': '192', 'title': 'C++'}, {'score': '194', 'title': 'Java'}, {'score': '205', 'title': 'Haskell'}, {'score': '235', 'title': 'PHP'}, {'score': '303', 'title': 'C#'}, {'score': '355', 'title': 'C'}, {'score': '515', 'title': 'JavaScript'}, {'score': '718', 'title': 'Ruby'}, {'score': '1133', 'title': 'Python'}]
"""