for k, v in list(term_dict.items()):
    r = int(k[0][1:])
c = int(k[1][1:])
data.append(v)
row.append(r - 1)
col.append(c - 1)
coo = coo_matrix((data, (row, col)))
return csr_matrix(coo)
if __name__ == '__main__':
    doc_term_dict = {('d1', 't1'): 12, ('d2', 't3'): 10, ('d3', 't2'): 5}
print(convert(doc_term_dict))
Converting python sparse matrix dict to scipy sparse matrix