I have a nested list of words
with lots of duplicates, and a list of uniquewords
which is a set of the list words
. I want to find the minimum starting point of an item in word. For instance:
words = [['apple',5],['apple',7],['apple',8],['pear',9], ['pear',4]
['grape',6],['baby',3],['baby',2],['baby',87]]
uniquewords = ['apple','pear','grape','baby']
I want a final result as:
[0,3,5,6]
I tried using enumerate()
, because index()
does not work on a nested list.
a = []
>>> for i in range(len(uniquewords)):
... for index,sublist in enumerate(words):
... if uniquewords[i] in sublist:
... a.append(min(index))
...
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
TypeError: 'int' object is not iterable
I'm sensing that this does not work, because I'm not telling python to append the indexes for each of the uniquewords. How would I get there?