SciPy

scipy.sparse.dok_matrix.iterkeys

dok_matrix.iterkeys() → an iterator over the keys of D