python - search times of "x in []" vs "x in {}" -
i ran problem have go through proxy logs see if users have visited list of sites.
i wrote small script read proxy logs, matching visited host against list:
for proxyfile in proxyfiles: line in proxyfile.readlines(): if line[4] in hosts_list: print line the hosts_file large, talking ~10000 hosts, , noticed searching took longer expected.
i wrote small test:
import random, time test_list = [x x in range(10000)] test_dict = dict(zip(test_list, [true x in range(10000)])) def test(test_obj): s_time = time.time() in range(10000): random.randint(0,10000) in test_obj d_time = time.time() - s_time return d_time print "list:", test(test_list) print "dict:",test(test_dict) the result following:
list: 5.58524107933 dict: 0.195574045181 so, question. possible perform search in more convenient way? creating dictionary of list seems hack, want search key , not value contains.
"as want search key , not value contains" => use set
Comments
Post a Comment