how to search item in list of list

Larry Hudson orgnut at yahoo.com
Tue Jun 14 00:45:42 EDT 2016


On 06/12/2016 08:29 PM, meInvent bbird wrote:
> 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')]]
>

I (manually) reformatted your list and found you have a missing left square bracket in the middle.
But the way your list is formatted here I really can't tell you where it is -- you'll have to 
reformat
it and/or use an editor that highlights matching brackets to find it yourself.  Most programming
editors have that bracket matching capability.

-- 
      -=- Larry -=-


More information about the Python-list mailing list