Twitter ユーザーのリストの json 表現を含むファイルから、各ユーザーのスクリーン名 ('screen_name') とフォロワー数 ('followers_count') を返す関数を定義しようとしています。
ファイルの例 (短縮)` (...)
"followers_count": 1815974,
"follow_request_sent": false,
"followers_count": 22928633,
"screen_name": "twitterapi",
"favourites_count": 22,
"follow_request_sent": false,
"followers_count": 22928633,
"screen_name": "twitter",
(...)`
次のようなものが返されます。
>>> followers_counts(open(input))
{u’twitter’: 22928633, u’twitterapi’: 1815974}
これは私がこれまでに得たものです。ご覧のとおり、私はこれがあまり得意ではありません。
def followers_counts(input):
tweet = json.loads(input)
name = tweet["screen_name"]
count = tweet["followers_count"]
print "u '(1)':(2)".format(name, count)