【问题标题】:how to Write a function that takes a list of strings as input, and returns the count of the number of strings [closed]如何编写一个将字符串列表作为输入的函数,并返回字符串数的计数[关闭]
【发布时间】:2014-01-09 03:16:02
【问题描述】:
字符串长度应为 2 或更多,并且字符串的第一个字符和最后一个字符应相同。
我正在尝试编写一个函数,该函数将字符串列表作为输入,并返回字符串长度应为 2 或更多且字符串的第一个和最后一个字符应相同的字符串数的计数.
【问题讨论】:
标签:
python
string
list
python-2.7
char
【解决方案1】:
我会做以下事情:
def special_strings_count(strings):
return len([x for x in strings if len(x) > 1 and x[0] == x[-1]])
strings = [] # your list of strings
print special_strings_count(strings)