As a rule I don't like to trigger exceptions, even controlled ones. One reason is that they are more expensive to handle, and as the name implies they should remain exceptions.
So rather than doing this:
bond = open('/proc/net/bonding/%s' % iface).read()
print "ERROR: Invalid interface %s\n" % iface
Thank you for the great question and the great review @Peilonrayz ! Don't have much to criticize, only a few things which I would personally change. It's my first heap implementation, so please double check my suggestions...
Getting the parent/child is a bit of magic numbering, maybe put that into a separate function
Both in heapify/inv_heapify the words ...
For me, this is a little bit unclear
def list_diff(list1, list2):
"""Returns a new list with the items in list1 that do not belong to list2"""
return list(set(list1) - set(list2))
since you don't just return a new list with the items in list1 that are not in list2, but you also remove duplicates from list1 (which maybe is what you want to do?), and ...
BUG: Your main loop for l in substrings(a): ... will return the first palindrome it finds inside a (stepping the indices back from the end), not just the longest one. If there are multiple longest palindromes it won't return them all, only the first it finds. Your code is overly tailored to this one example. Use other examples to tickle it, e.g. "zaba ...