Skip to content

Instantly share code, notes, and snippets.

@valericus
Created January 22, 2016 02:16
Show Gist options
  • Save valericus/ae92ccc25d098ae71210 to your computer and use it in GitHub Desktop.
Save valericus/ae92ccc25d098ae71210 to your computer and use it in GitHub Desktop.
def top_10_ip(file_object):
result = {}
for line in file_object:
ip = line.split()[0]
if result.setdefault(ip, 1):
result[ip] += 1
return sorted(result, key=lambda x: result[x], reverse=True)[:10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment