Search
 
SCRIPT & CODE EXAMPLE
 

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']))
Comment

PREVIOUS NEXT
Code Example
Python :: sort a stack using recursion 
Python :: # time delay in python script 
Python :: PIL image example 
Python :: python merge lists 
Python :: pandas write to excel 
Python :: python test if string begins with python 
Python :: count unique pandas 
Python :: timestamp to date time till milliseconds python 
Python :: python remove special characters from list 
Python :: python kivy 
Python :: create column for year in dataframe python 
Python :: spawn shell using python 
Python :: create an array of n same value python 
Python :: json python 
Python :: convert python datetime to string 
Python :: Iterating With for Loops in Python Using range() and len() 
Python :: python list length 
Python :: python iterate through files 
Python :: get hash python 
Python :: python iterate through string in reverse 
Python :: summary in python 
Python :: decision tree algorithm python 
Python :: repeat array along new axis 
Python :: plt.annotate text size 
Python :: django unique together 
Python :: dropout keras 
Python :: validate ip address python 
Python :: how to clear a list in python 
Python :: list of seaborn color palette 
Python :: python remove repeated elements from list 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =