Rosetta Code/Rank languages by popularity: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Python}}: better, in my opinion) |
||
Line 24: | Line 24: | ||
<python>import urllib |
<python>import urllib |
||
import re |
import re |
||
def key1(x): |
def key1(x): |
||
return int(x.split()[0]) |
return int(x.split()[0]) |
||
⚫ | |||
a = urllib.urlopen("http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=500") |
a = urllib.urlopen("http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=500") |
||
a = a.read().strip().split("\n") |
|||
⚫ | |||
for line in a: |
|||
match = re.search('>([^<>]*)</a> \((\d+) members?\)', line) |
|||
if match: |
|||
del a[0] |
|||
entries.append(match.group(2) + ' - ' + match.group(1)) |
|||
del a[-1] |
|||
⚫ | |||
for i in a: |
|||
⚫ | |||
test.append(re.findall("\(.* members\)",i)[0].split()[0].replace("(",'') + " - "+\ |
|||
re.findall('Category:.*" ',i)[0].replace('"','').split(":")[1]) |
|||
c = 1 |
|||
⚫ | |||
⚫ | |||
c += 1</python> |
Revision as of 05:32, 24 January 2009
Rosetta Code/Rank languages by popularity
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Sort most popular programming languages based in number of members in Rosetta Code categorys (from http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=500)
Output:
1. 246 - Programming_Tasks 2. 203 - Python 3. 201 - Ada 4. 188 - OCaml 5. 171 - Perl 6. 169 - Java 7. 168 - Haskell 8. 157 - C 9. 141 - Forth 10. 140 - Ruby ...
Filtering wrong results is optional.
Python
<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 = [] for line in a:
match = re.search('>([^<>]*)</a> \((\d+) members?\)', line) if match: entries.append(match.group(2) + ' - ' + match.group(1))
for c, line in enumerate(sorted(entries, key=key1, reverse=True)):
print "%3s. %s" % (c+1, line)</python>