I'm running a recursive function on sublist to search the element check_value in the list once it finds it, it verifies whether other_value is the first item of the corresponding list and finally return the index.But current code is returning None.can anyone please support as I'm not having much understanding on recursive functions functioning on sublists.
def check_with_list(dd, check_value, other_value=None):
global new_index
for index, h in enumerate(dd):
if isinstance(h, list):
result = check_with_list(h, check_value)
if result is not None:
if other_value:
new = (index,) + result
if len(new) == 2:
if not dd[new[0]][0] == other_value:
result = None
else:
return (index,) + result
elif h == check_value:
return (index,)
# value not found
return None
dd = [
"gcc",
"fcc",
["scc", "jhh", "rrr"],
["www", "rrr", "rrr"],
"mmm",
["qwe", ["ree", "rer", "rrr"], "ere"]
]
dd = check_with_list(dd, "rrr", "ree")
print(dd)