The return of a python recusion differs and I do not understand why:
from bs4 import BeautifulSoup
def recurse_table(table, table_list):
if table.find_next("table") is not None:
recurse_table(table.find_next("table"), table_list)
table_list.append(table)
return table_list
fp = open("tc4400_cs_2.html")
soup = BeautifulSoup(fp.read(), features="html.parser")
print(len(recurse_table(soup.find("table"), [])))
returns correct length (4).
Whereas
from bs4 import BeautifulSoup
def recurse_table(table, table_list):
if table.find_next("table") is not None:
recurse_table(table.find_next("table"), table_list)
return table_list.append(table)
fp = open("tc4400_cs_2.html")
soup = BeautifulSoup(fp.read(), features="html.parser")
print(len(recurse_table(soup.find("table"), [])))
returns TypeError: object of type 'NoneType' has no len()
What am I missing?