(May-23-2018, 04:21 PM)fad3r Wrote:def not_bad(s): t = s.split() for x in t: if x == "not": a = t.index(x) if x == "bad": b = t.index(x) if a < b: newlist = [range (a, b)] del t[newlist] print (t)
a
only exists if x=="not"
. You can't reference something that doesn't exist.As was previously mentioned, you can fix this by simply defining your variables before hand with default values.