I have a list named mylist. If I enter print mylist in my program and I am able to print my list and see the items. I then transfer the list items into a heap queue:
myheap=heapq.heapify(mylist)
print myheap
It prints None. What is wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You failed to read the docs:
The
heapify()method convers the list in-place, it doesn’t return a new list. You should printmylist:As pointed out in a comment, this is a bit odd for a Pythonn API. I don’t know for certain, but I guess it has been done for efficiency’s sake. Still, of course the
heapify()function could just return the input reference, to make it less surprising.If the API had been a constructor, which returns a newly constructed object like you expected, it would very probably have been named differently, perhaps:
The casing and naming of the function are both strong hints this is not a regular constructor.