I was trying to find the maximum element of a heap and found a function heapq.nlargest to use.
Then got this error at the line commented below:
TypeError at line 10: 'NoneType' object is not iterable.
So here is the code:
from heapq import *
from math import ceil
number_of_elements, size_of_window = 10, 10
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
first_window = sorted(array[:size_of_window])
lower_set = first_window[:ceil(size_of_window / 2)]
lower_set_heap = heapify(lower_set)
print(nlargest(1,lower_set_heap)) # got TypeError here
heapifymodifies the argument in-place:Thus, in
lower_set_heap = heapify(lower_set),lower_set_heapwill beNone:You should just write
heapify(lower_set)and thenlower_setis your heap: