#!/usr/bin/python
#Dictionary editing script
#Copyright Jack Breese, 2006
#Liscensed under the terms of the GNU GPL
#This file may be freely used and distributed as per the terms of the GPL
def main():
	dict = open(raw_input("Name of dictionary file? ")).read().split()
	while True:
		ad = raw_input("Add or delete word (add/delete/done)? ")
		if "a" in ad:
			word = raw_input("Word to add? ")
			if not word in dict:
				dict.append(word)
			else:
				print "Word already in dictionary."
		elif not ad == "done":
			word = raw_input("Word to delete? ")
			if not word in dict:
				print "Word not in dictionary."
			else:
				ind = dict.index(word)
				del dict[ind]
		else:
			break
	dict.sort()
	wfile = raw_input("Filename to write to? ")
	f = open(wfile, 'w')
	f.write("\n".join(dict))
	print "Dictionary saved."

main()


