Created
May 2, 2017 10:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
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 = 0for word in words:
if len(word) > 1 and word[0] == word[-1]:
ctr += 1
return ctrprint(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
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