Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Taking a list of strings as input, our matching function returns the count of the number of strings whose first and last chars of the string are the same. Also, only consider strings with length of 2 or more. python

def matchWords(words):
    counter = 0
    for word in words:
        if len(word) > 1 and word[0] == word[-1]:
            counter += 1
    return counter
print(matchWords(['abc', 'xyz', 'aba', '1221']))
 
PREVIOUS NEXT
Tagged: #Taking #list #strings #matching #function #returns #count #number #strings #chars #string #strings #length #python
ADD COMMENT
Topic
Name
2+6 =