Skip to content

Instantly share code, notes, and snippets.

@amkatrutsa
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save amkatrutsa/2ecf7b7267dd752bf3dd to your computer and use it in GitHub Desktop.

Select an option

Save amkatrutsa/2ecf7b7267dd752bf3dd to your computer and use it in GitHub Desktop.
# First version: len(person_id) = 15352
person_id = {}
with open(in_dir + 'ID-title_dict.pickle', 'rb') as f:
id2title = cPickle.load(f)
with open(in_dir + 'person_id.txt') as f:
for p_id in f:
try:
t = id2title[int(p_id)]
person_id[int(p_id)] = 0
except KeyError:
continue
print "Number of person's id", len(person_id)
# Second version: len(person_id) = 30497
person_id = []
with open(in_dir + 'ID-title_dict.pickle', 'rb') as f:
id2title = cPickle.load(f)
with open(in_dir + 'person_id.txt') as f:
for p_id in f:
try:
t = id2title[int(p_id)]
person_id.append(int(p_id))
except KeyError:
continue
print "Number of person's id", len(person_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment