1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#!/usr/bin/python
# Python script for combining several journal abbreviation lists
# and producing an alphabetically sorted list. If the same journal
# names are repeated, only the version found last is retained.
#
# Usage: combineJournalLists.py outfile infile1 infile2 ...
import sys
import fnmatch
import os
outFile = sys.argv[1]
dictionary = dict()
for i in range(2,len(sys.argv)):
count = 0
f = open(sys.argv[i], "r")
for line in f:
if line[0] != "#":
count = count+1
parts = line.partition("=")
dictionary[parts[0].strip()] = line.strip()
f.close()
print sys.argv[i]+": "+str(count)
print "Combined key count: "+str(len(dictionary))
f = open(outFile, "w")
for key in sorted(dictionary.iterkeys()):
f.write(dictionary[key]+"\n")
f.close()
|