How to use a array of heaps in python
Question: I need to create and use n heaps, I am trying to use heapq and is trying to
push elements into a list of lists, where each element is to be considered a
seperate heap. But its behaving weirdly. I just wanna push the elements 6 and
7 into my 3rd heap. but its getting pushed into all my heaps. any way out of
this??

    
    
    >>> test
    [[], [], [], []]
    >>> 
    >>> heappush(test[2],6)
    >>> heappush(test[2],7)
    >>> test
    [[6, 7], [6, 7], [6, 7], [6, 7]]
    


Answer: You seem to have created `test` something like this:

    
    
    >>> from heapq import heappush
    >>> test = [[]] * 4
    >>>
    >>> heappush(test[2],6)
    >>> heappush(test[2],7)
    >>> test
    [[6, 7], [6, 7], [6, 7], [6, 7]]
    

This creates four references to the _same_ list object. Use a list
comprehension to make four distinct lists:

    
    
    >>> test = [[] for _ in range(4)]
    >>> heappush(test[2],6)
    >>> heappush(test[2],7)
    >>> test
    [[], [], [6, 7], []]
    

