Rosetta Code/Rank languages by popularity: Difference between revisions
Content added Content deleted
(removed semicolon, ignore this. (This happens when you learn C++.)) |
(added enumerate + exaplanation) |
||
Line 455: | Line 455: | ||
Fail-proof solution |
Fail-proof solution |
||
This solution is using "categoryinfo", this example will work with more than 500 categories (It does not read Special:Categories), and with more than 500 programming languages. |
|||
<lang python>import json |
<lang python>import json |
||
Line 463: | Line 465: | ||
langs = json.load(urllib.urlopen("http://www.rosettacode.org/w/api.php?\ |
langs = json.load(urllib.urlopen("http://www.rosettacode.org/w/api.php?\ |
||
action=query&list=categorymembers&cmtitle=Category:Programming_Languages\ |
action=query&list=categorymembers&cmtitle=Category:Programming_Languages\ |
||
&cmlimit=500&format=json")) |
&cmlimit=500&format=json")); |
||
titles = [i['title'] for i in langs['query']['categorymembers']] |
titles = [i['title'] for i in langs['query']['categorymembers']] |
||
Line 482: | Line 484: | ||
del titles[:50] |
del titles[:50] |
||
c = 0 |
|||
for i in sorted(result,key=lambda x: x[1],reverse=True): |
for n, i in enumerate(sorted(result,key=lambda x: x[1],reverse=True)): |
||
⚫ | |||
c += 1 |
|||
⚫ | |||
=={{header|Ruby}}== |
=={{header|Ruby}}== |