【发布时间】:2015-05-17 06:54:23
【问题描述】:
我有一个这样的 .csv 文件,它有单词和值:
string1, 102, 90, 23
string2, 89, 45, 21
...
hi, 1, 3, 5
example, 2, 0, 2
someone, 1, 1, 1
hope, 0, 0, 0
stringN, 923, 23892, 9292
stringnN-1, 2903, 49058, 4859
还有很多这样的单词:
lis__ = [[Hi this is an example, this site is nice!.],...,[I hope someone can help]]
如何返回出现在lis__ 中的每个单词的值的总和。对于上述实例,输出将是这样的:
对于第一个子列表:
[Hi this is an example, this site is nice!.]
In:
hi, 1, 3, 5
example, 2, 0, 2
someone, 1, 1, 1
hope, 0, 0, 0
Then add value one with value one, two with two and three with three:
Out:
[(3,3,7)]
然后对于第二个子列表,将值 1 与值 1、2 与 2、3 与 3 相加:
In:
[I hope someone can help]
hi, 1, 3, 5
example, 2, 0, 2
someone, 1, 1, 1
hope, 0, 0, 0
out:
[(1,1,1)]
最后:
[(3,3,7),...,(1,1,1)]
其中... 是无限的字符串或元组。可能这个任务可以用csv 模块来完成,知道如何解决这个问题吗?提前谢谢各位!
【问题讨论】:
标签: python list python-2.7 parsing csv