Python中文
首页
教程
问答
标签
搜索
登录
注册
做列表python的数学运算
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我想从现有列表创建一个列表。在</p> <p>原始列表:</p> <pre><code>mylist = ["single extra", "double double", "tripple, double, singe", "mohan point tripple decker","one","covent gardens london tw45hj", "honda"] </code></pre> <p>找出mylist中每个标签的字数:</p> ^{pr2}$ <p>打印数字字</p> <pre><code>[2, 2, 3, 4, 1, 4, 1] </code></pre> <p>让我们假设我的列表是一个很长的字符串</p> <pre><code>"single extra double double tripple double singe mohan point tripple decker one covent gardens london tw45hj honda" </code></pre> <p>我想弄清楚每个标签从那张长长的单子上开始。在</p> <p>所以我知道在原始列表中,“mylist”的第一个索引有2个单词,所以它从0开始到2,然后下一个索引包含2个单词,所以从3开始到5,依此类推。。。在</p> <p>手动计算如下:</p> <pre><code>1 + 2 = 3 3 + 2 = 5 5 + 3 = 8 8 + 4 = 12 12 + 1 = 13 13 + 4 = 17 17 + 1 = 18 </code></pre> <p>我试过了:</p> <pre><code>p=0 x=1 for i, item in enumerate(num_words): result = num_words[p] + num_words[x] results = result + num_words[x] x += 1 p += 1 </code></pre> <p>打印结果</p> <p>但这失败了。。。在</p> <p>我希望这有意义。。。。。在</p> <p>谢谢大家</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你想做的就是跑步总量。您可以使用简单循环:</p> <pre><code>>>> res, c = [], 1 >>> for x in num_words: ... c += x ... res.append(c) >>> res [3, 5, 8, 12, 13, 17, 18] </code></pre> <p>也可以用功能风格的一行来完成,比如:</p> ^{pr2}$
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
2 回答
将Pandas数据帧转换为scipy稀疏矩阵
10 回答
将Pandas数据帧转换为Spark Datafram时出现问题
3 回答
将pandas数据帧转换为spark DataFram时出错
4 回答
将Pandas数据帧转换为spark datafram时收到错误
10 回答
将Pandas数据帧转换为Spark数据帧
10 回答
将Pandas数据帧转换为Tensorflow数据
7 回答
将Pandas数据帧转换为tkinter obj
7 回答
将pandas数据帧转换为XML
8 回答
将Pandas数据帧转换为值sql语句
1 回答
将pandas数据帧转换为元组
2 回答
将pandas数据帧转换为元组列表
6 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
4 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
1 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
6 回答
将pandas数据帧转换为内存中类似文件的对象?
4 回答
将Pandas数据帧转换为内存功能(&F)
10 回答
将pandas数据帧转换为列表列表
7 回答
将pandas数据帧转换为列表列表以输入到RNN
8 回答
将Pandas数据帧转换为单行DataFram
6 回答