At 2008-06-17T05:55:52Z, Chris <[EMAIL PROTECTED]> writes:
> Is anyone aware of any prior work done with searching or matching a
> pattern over nested Python lists? I have this problem where I have a
> list like:
>
> [1, 2, [1, 2, [1, 7], 9, 9], 10]
>
> and I'd like to search for the pattern [1, 2, ANY] so that is returns:
>
> [1, 2, [1, 2, [6, 7], 9, 9], 10]
> [1, 2, [6, 7], 9, 9]
Hint: recursion. Your general algorithm will be something like:
def compare(list, function):
if function(list):
print list
for item in list:
if item is a list:
compare(item, function)
def check(list):
if list starts with [1, 2] and length of the list > 2:
return True
else:
return False
--
Kirk Strauser
The Day Companies
--
http://mail.python.org/mailman/listinfo/python-list