I have a list:
l = [[\'en\', 60, \'command\'],[\'sq\', 34, \'komand\']]
I want to search for komand
or sq
and get
You can do it this way:
def find(value, seq):
for index, item in enumerate(seq):
if value in item:
return index, item
In [10]: find('sq', [['en', 60, 'command'],['sq', 34, 'komand']])
Out[10]: (1, ['sq', 34, 'komand'])
Or if you want a general solution:
def find(fun, seq):
for index, item in enumerate(seq):
if fun(item):
return index, item
def contain(value):
return lambda l: value in l
In [14]: find(contain('komand'), [['en', 60, 'command'],['sq', 34, 'komand']])
Out[14]: (1, ['sq', 34, 'komand'])