Created
April 10, 2012 07:42
-
-
Save TkTech/2349101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-> % python silly_ip.py | |
{74: {125: {232: {211: 1, 20174: 1}}}, 79: {115: {74: {141: 1}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf8 -*- | |
import sys | |
dummy_data = [ | |
'74.125.232.201' | |
'74.125.232.206', | |
'74.125.232.211', | |
'79.115.74.141' | |
] | |
def main(argv): | |
root = {} | |
for raw_ip in dummy_data: | |
ip = [int(i) for i in raw_ip.split('.')] | |
tmp = root.setdefault(ip[0], {}) | |
tmp = tmp.setdefault(ip[1], {}) | |
tmp = tmp.setdefault(ip[2], {}) | |
tmp[ip[3]] = tmp.get(ip[3], 0) + 1 | |
print root | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment