Beginner here (meaning I probably did something silly):
I am trying to target indexed elements that have [A], in them. Entries for 'scarcity' and 'sweet' are both shown.
I am running into trouble when index item[2] is empty. I get the following message:
['scarcity', 'scarce', '[A],', 'ity', '[N|A]', '[N]']
scarcity scarce [A], ity [N|A] [N]
scarcity
[A],
['sweet', ',']
sweet ,
Traceback (most recent call last):
File "final3.py", line 69, in <module>
dict_pos = item[2]
IndexError: list index out of range
This is what the code is:
for line in dictionary:
line = line.replace('(', ' ').replace(')', ' ')
item = line.split()
print item
print line
dict_word = item[0]
dict_base = item[1]
dict_pos = item[2]
print dict_word
if not dict_pos:
print "[X],"
else:
print dict_pos
Any thoughts?
Thank you!