how to search item in list of list

meInvent bbird jobmattcon at gmail.com
Sun Jun 12 23:29:35 EDT 2016


once a nested list have a word "node" then true else false

def search(current_item):
    if isinstance(current_item, list):
        if len(current_item)==4: 
            if [item for item in current_item if item[4] == "node"] != []:
                return True
        if True in [search(item) for item in current_item]:
            return True
        else:
            return False

search(mresult)

but it return false


mresult = [[(2, {'11': 1, '10': 1, '00': 0, '01': 1}, ['000', '001', '010', '011', '100',
'101', '110', '111'], 'xy', 'start')], [(2, {'11': 1, '10': 1, '00': 0, '01': 1}
, ['000', '001', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2
, {'11': 1, '10': 1, '00': 0, '01': 1}, ['000', '001', '010', '011', '100', '101
', '110', '111'], 'xz', 'start')], [(2, {'11': 1, '10': 0, '00': 0, '01': 0}, ['
000', '001', '010', '011', '100', '101', '110', '111'], 'xy', 'start')], [(2, {'
11': 1, '10': 0, '00': 0, '01': 0}, ['000', '001', '010', '011', '100', '101', '
110', '111'], 'yz', 'start')], [(2, {'11': 1, '10': 0, '00': 0, '01': 0}, ['000'
, '001', '010', '011', '100', '101', '110', '111'], 'xz', 'start')], [(2, {'11':
 1, '10': 0, '00': 1, '01': 1}, ['000', '001', '010', '011', '100', '101', '110'
, '111'], 'xy', 'start')], [(2, {'11': 1, '10': 0, '00': 1, '01': 1}, ['000', '0
01', '010', '011', '100', '101', '110', '111'], 'yz', 'start')], [(2, {'11': 1,
'10': 0, '00': 1, '01': 1}, ['000', '001', '010', '011', '100', '101', '110', '1
11'], 'xz', 'start')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '01', '
11', '11', '10', '11', '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00'
: 0, '01': 1}, ['00', '01', '10', '11', '11', '11', '11', '11'], 'xy', 'node')],
 [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00', '00', '10', '10', '10', '10',
 '11', '11'], 'xy', 'node')], [(1, {'11': 1, '10': 1, '00': 0, '01': 1}, ['00',
'00', '10', '11', '10', '10', '10', '11'], 'xy', 'node')], [(1, {'11': 1, '10':
1, '00': 0, '01': 1}, ['00', '00', '10', '10', '10', '11', '10', '11'], 'xy', 'n
ode')]]


More information about the Python-list mailing list