Hi, from next time onwards you need to place your code between 'Code' tag.
for eg: I will code in reverse order to refrain its affect,
[/code]
your code goes here...
[Code = Python]
I have assumed the input file like following,
accronym.txt
--------------
IIMB-Indian Institute of Management, Bangalore
ASCII-American Standard Code for Information Interchange
PERL-Practical Extraction and Reporting Language
ANSI-American National Standards Institute
ANSI-Advanced Neuromodulation Systems, Inc
--------------
try:
fp = open("1.txt", 'r')
acronym_dictionary = dict()
for line in fp.readlines():
if acronym_dictionary.has_key(line.split('-')[0]):
acronym_dictionary[line.split('-')[0]].append(line.split('-')[1])
else:
acronym_dictionary[line.split('-')[0]] = [ line.split('-')[1] ]
fp.close()
acronym = raw_input("Enter an acronym")
if acronym_dictionary.has_key(acronym):
for expansion in acronym_dictionary[acronym]:
print expansion
except IOError, e:
print e
except IndexError:
pass
I have used dictionary(or hash) to keep the details. Acronym is key and its expansion is its value. I have used list to keep expansions. Because if an acronym has more than one expansion then it does not violate the dictionary rule. That is key should be unique in dictionary.
hope this helps...
kath.