After displaying, return a special value and then check the return variable of foo. If it is that special value, it is directly based on the return value
需要有退出条件, 比如检查一段数据中是否有unicode字符
def check_unicode(data):
"""
:param data:
:return:
"""
if isinstance(data, dict):
for k, v in data.iteritems():
if isinstance(v, dict):
if check_unicode(v):
return True
elif isinstance(v, list):
if check_unicode(v): # 检查为True退出
return True
else:
if v and isinstance(v, unicode):
return True
elif isinstance(data, list):
for v in data:
if isinstance(v, dict):
if check_unicode(v):
return True
elif isinstance(v, list):
if check_unicode(v):
return True
else:
if v and isinstance(v, unicode):
return True
else:
if data and isinstance(data, unicode):
return True
return False
After displaying, return a special value and then check the return variable of foo. If it is that special value, it is directly based on the return value
For problems that are too vague, you can only analyze them through the code.
Recursion requires exit conditions, which is what you call stopping. .
Generally, a branch judgment is required inside recursion, such as:
After recursing a certain number of times and reaching the above if condition, the recursion ends.
Just add a return after displaying