3 def sort_items(input_filename, output_filename):
4 input_file = open(input_filename,
"r")
7 for line
in input_file:
11 key, value = line.split(
"\t")
14 while value[-1] ==
"\n" or value[-1] ==
"\r":
20 output_file = open(output_filename,
"w")
22 for key
in sorted(dic.iterkeys()):
23 output_file.write(key +
"\t" + dic[key] +
"\n")
27 def reverse_items(input_filename, output_filename):
28 input_file = open(input_filename,
"r")
31 for line
in input_file:
34 key, value = line.split(
"\t")
35 while value[-1] ==
"\n" or value[-1] ==
"\r":
38 value_list = value.split(
" ")
39 for value
in value_list:
40 if dic.has_key(value):
41 dic[value].append(key)
47 output_file = open(output_filename,
"w")
49 for key
in sorted(dic.iterkeys()):
50 output_file.write(key +
"\t" +
" ".join(dic[key]) +
"\n")
54 def find_target_items(input_filename, keyword):
55 input_file = open(input_filename,
"r")
56 for line
in input_file:
59 key, value = line.split(
"\t")
60 while value[-1] ==
"\n" or value[-1] ==
"\r":
63 value_list = value.split(
" ")
64 for value
in value_list: