Skip to content

Instantly share code, notes, and snippets.

@tau0
Created November 3, 2014 18:05
Show Gist options
  • Save tau0/edab90647697b9e1415a to your computer and use it in GitHub Desktop.
Save tau0/edab90647697b9e1415a to your computer and use it in GitHub Desktop.
codeforces tags distribution
import json
import urllib2
url = "http://codeforces.com/api/problemset.problems"
data = json.dumps({})
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
f = urllib2.urlopen(req)
response = f.read()
f.close()
data = json.loads(response)
counter = dict()
problems = data["result"]["problems"]
for problem in problems:
if "tags" in problem:
for tag in problem["tags"]:
if not tag in counter:
counter[tag] = 0
counter[tag] += 1
import operator
sorted_x = sorted(counter.items(), key=operator.itemgetter(1), reverse=True)
for line in sorted_x:
print line[0] + ' ' + str(line[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment