Create a function that as an argument gets a list of strings and returns the number of elements matching the conditions.
def count_string(arg_list):
result = 0
for item in arg_list:
if (len(item) >= 2 and item[0] == item[-1]):
result += 1
return result
Example of a function in a python interpreter:
Word1= ['aba', 'xyz', 'aa', 'x', 'bbb']
count_string(Word1)
3
Comments
Leave a comment