假设我有下面的单词我想放在一个列表中
"cat,dog,fish" (first row)
"turtle,charzard,pikachu,lame" (second row)
"232.34,23.4,242.12%" (third row)
我的问题是如何计算每行中的令牌,比如第一行有3个,第二行有4个,第三行有3个。在那之后,我如何计算字符数,然后决定每一行的字符数最多?所以输出看起来像
^{pr2}$
只使用len()等简单的列表方法。并使用逗号作为分隔符。每次我都会用逗号来代替我,因为我每次都会输
Tags:
给定字符串列表:
试试这个。同时适用于
Python2
和Python3
结果:
^{pr2}$编辑:
现在使用
max
而不是我愚蠢的选择sort
来寻找最长的单词,灵感来自@inspector4dget的答案。在假设您有一个逗号分隔的行文件:
相关问题 更多 >
编程相关推荐