Simply remove the assignment from
result = result.sort()
leaving just
result.sort()
The sort
method works in-place (it modifies the existing list), so no assignment is necessary, and it returns None
. When you assign its result to the name of the list, you're assigning None
.
It can easily (and more efficiently) be written as a one-liner:
max(len(Ancestors(T,x)) for x in OrdLeaves(T))
max
operates in linear time, O(n), while sorting is O(nlogn). You also don't need nested list comprehensions, a single generator expression will do.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…