Feb-04-2017, 05:21 AM
Python 2.7.10
I can't seem to figure out the way to do this. Here is the code
I can't seem to figure out the way to do this. Here is the code
something = "go dumb cat" words = something.split() word_one = ('noun', 'cat') word_two = ('verb', 'go') sentence = [word_one, word_two] listing = [] for each in words: for x in sentence: if each in x: pass listing.append(x) else: listing.append(('error', x[1])) print listingI'm not surprised that the above didn't do what I want. Here is the output.
Output:[('error', 'cat'), ('verb', 'go'), ('error', 'cat'), ('error', 'go'), ('noun', 'cat'), ('error', 'go')]
The else is where I get the output I don't want, with just the if I get the following (and the more I try to figure it out, the more I'm surprised that this part works how I want it to)Output:[('verb', 'go'), ('noun', 'cat')]
This is what I would want it to do. Output:('verb', 'go'), ('noun', 'cat'), ('error', 'dumb')]