编写一个程序,该程序返回的字符串列表中的字符串数超过10个字符。
我的程序:
def count(List):
if len(List) > 10:
x = "".count(List)
if len(List) <= 10:
x = "None"
return x
def main():
Listy = input("Please enter a list of strings: ")
s = []
for i in Listy:
Split = i.replace("[","").replace('"','').replace("]","").split(",")
s += Split
y = count(s)
print(y)
main()
我写了这个程序,但是似乎count()
函数有问题。我不知道为什么。
这将为您提供列表中有多少个单词超过10个字符:
注意:我使用过,raw_input
因为我input
在Python 3中使用Python 2.7 ,因此用户也必须输入用逗号和空格分隔的单词
strings = raw_input("Please enter words divided by comma and white space: ")
x = strings.split()
y = []
for i in x:
if len(i) > 10:
y.append(i)
print len(y)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句