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 ::  
:: remove unnamed 0 column pandas 
::  
Python ::  
::  
Python ::  
Python ::  
::  
:: setting p a virtual envioronment 
::  
::  
::  
::  
::  
Python ::  
Python ::  
Python ::  
::  
::  
::  
Python ::  
Python ::  
::  
Python :: pandas replace values based on condition 
Python ::  
Python :: Plotly set axes labels 
Python ::  
Python :: pandas create column if equals 
::  
:: removing whitespaces from pandas dataframe csv 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =