小编Rom*_*ker的帖子

返回列表中最长单词的len

嗨,我正在尝试创建一个python程序,它将返回列表中最长单词的长度,但它对我来说效果不好.

这是代码:

def find_longest_word():
   list1 = ['a','aa','aaa','aaaa','aaaaa','aaaaaa','aaaaaaa','aaaaaaaa',]
   max1 = ''
   for x in range (0, len(list1)):
      if (len(max1) < len(list1[x]) ):
          max1 = list1[x]
   return max1    


def main():
    m = find_longest_word()
    print len(m)
Run Code Online (Sandbox Code Playgroud)

python list maxlength python-2.7

1
推荐指数
1
解决办法
2679
查看次数

如何有效地使用strip()函数

你能告诉我为什么strip()函数不起作用吗?

str1= 'aaaadfffdswefoijeowji'

def char_freq():
    for x in range (0, len(str1)):
        sub = str1[x]
        print 'the letter',str1[x],'appearence in the sentence=', str1.count(sub, 0,len(str1))
        str1.strip(str1[x])

def main():
    char_freq()

main()
Run Code Online (Sandbox Code Playgroud)

python

-1
推荐指数
1
解决办法
122
查看次数

标签 统计

python ×2

list ×1

maxlength ×1

python-2.7 ×1