Python2.7, the use of import matplotlib results in function output being assigned to a list twice
Question: I've been testing the use of an accumulate function in the following python
code. This code works well in producing the correctly accumulated output,
however it assigns the output to the list "test" twice. If I comment out
'import matplotlib', it only assigns it once. I need to use matplotlib for the
rest of the code I'll be developing. I'd appreciate if anyone has some
suggestions about why this might be/ a workaround? Thanks:

    
    
    #!/usr/bin/env python2.7
    
    import os
    import sys
    import numpy as np
    import matplotlib
    import math
    from itertools import groupby, islice
    
    def accumulate(iterable): # in py 3 use itertools.accumulate
        ''' Simplified version of accumulate from python 3'''
        it = iter(iterable)
        total = next(it)
        yield total
        for element in it:
            total += element
            yield total
        print total
    
    x=[1,2,3,4]
    
    test=list(accumulate(x))
    
    print "test: ", test  # why does this print twice when matplotlib is imported?
    


Answer: It doesn't when I save this code in a text file named "test.py" with chmod 755
and run with "./test.py" on my linux box. I get

    
    
    10
    test:  [1, 3, 6, 10]
    

the 10 presumably comes from the line

    
    
    print total
    

If I comment out the line

    
    
    import matplotlib
    

it gives the same output

