Skip to content

Instantly share code, notes, and snippets.

@ehedaoo
Created May 2, 2017 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehedaoo/a217759f230e32a2eaf89e0dc3412c7b to your computer and use it in GitHub Desktop.
Save ehedaoo/a217759f230e32a2eaf89e0dc3412c7b to your computer and use it in GitHub Desktop.
Write a Python program to count the number of strings where the string length is 2 or more and the first and last character are same from a given list of strings.
# Write a Python program to count the number of strings
# where the string length is 2 or more
# and the first and last character are same from a given list of strings.
# Sample List : ['abc', 'xyz', 'aba', '1221']
def compare(a):
ctr = 0
for i in a:
if len(i) > 2 and i[0] == i[-1]:
ctr+= 1
return ctr
a = ['abc', 'xyz', 'aba', '1221', 'aaa', 'asdasdsada']
for i in a:
z = compare(a)
print(z)
@Prasanthraj2401
Copy link

Given a list of strings, return the count of the number of strings where the string length is 2 or more and the first and last chars of the string are the same.
def match_words(words):
ctr = 0

for word in words:
if len(word) > 1 and word[0] == word[-1]:
ctr += 1
return ctr

print(match_words(['kasthuri', 'amma', 'basil', '1221', 'malayalam']))

Can any one can solve in this instructions are given above plz tell me

@Prasanthraj2401
Copy link

Given a list of strings, return the count of the number of strings where the string length is 2 or more and the first and last chars of the string are the same.
def match_words(words):
ctr = 0

for word in words:
if len(word) > 1 and word[0] == word[-1]:
ctr += 1
return ctr

print(match_words(['kasthuri', 'amma', 'basil', '1221', 'malayalam']))

Can any one can solve in this instructions are given above plz tell me

Help me to solve guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment