Search code examples
pythonlistintegerindices

Check if a letter is in a bidimensional list


I have created a list containing the abecedary with a related words in a bidimensional list. but when i try to to find a word contained in the list and print the related words, it throws me:

TypeError: list indices must be integers, not list

Here is my code:

import parallel
import time
import string

abc=[['a','EB'], ['b','F8']]

print ("Write something: ")
text = raw_input()
lent=len(text)
print (lent)
p=parallel.Parallel()
text1=list(text)

for x in text1:
print (x)
    i=0
for i in abc:
    if x in abc[0][i]:
           print(abc[0][i])
       p.setData(int('0x'+abc[0][i],16))

 time.sleep(0.5)

Solution

  • >>> abc = [['a','EB'],['b','F8']]
    >>> for i in abc:
    ...    print i
    ...
    ['a', 'EB']
    ['b', 'F8']
    

    So you probably need this:

    for i in abc:
        if x == i[0]:
               print(i[1])