def front_x(words):
list2 = []
for word in words:
if word[0] == 'x':
list2.append(word)
words.remove(word)
words.sort()
list2.sort()
return list2 + words
def main():
print(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']))
if __name__ == '__main__':
main()
This is my code I'm trying to do this example:
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. Note: python does not have a ++ operator, but += works.
and the output is like this : ['xzz', 'axx', 'bbb', 'ccc', 'xaa']
The problem is the last element on the list don't go to the new list I created. What should I do?