Rosetta Code/Rank languages by popularity: Difference between revisions

m
→‎{{header|Python}}: not sure if need to close
(→‎{{header|Python}}: in my opinion its better to iterate the file than read it all in)
m (→‎{{header|Python}}: not sure if need to close)
Line 26:
<python>import urllib
import re
 
def key1(x):
return int(x.split()[0])
 
a = urllib.urlopen("http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=500")
 
entries = []
 
Line 37:
match = re.search('>([^<>]*)</a> \((\d+) members?\)', line)
if match: entries.append(match.group(2) + ' - ' + match.group(1))
 
a.close()
 
for c, line in enumerate(sorted(entries, key=key1, reverse=True),start=1):
print "%3d. %s" % (c, line)</python>
Anonymous user