输入:
word_list = ["a", "b","c","d", "e"]
input1 = [("b",20),("a",10)}
input2 = [("c",9)]
input3 = [("d",70)]
result = merge_blabla(word_list, [input1, input2, input3])
如果可以每次添加一行,则此行会更好:
result = init_blabla(word_list)
result.append_blabla(input1)
result.append_blabla(input2)
result.append_blabla(input3)
输出是这样的:
result
>> matrix(array(10,20,0,0,0), array(0,0,9,0,0), array(0,0,0,70,0))
result.colnames
>> ["a", "b", "c", "d", "e"]
实际上word_list
有 1M 个元素,结果是一个稀疏矩阵,所以效率可能很重要。
有没有人知道如何在 python 中做到这一点?