Here's my view -
def front_x(words):
What does this name mean? I have no idea what this method does - I should be able to tell just by the name. My guess is that it moves the words with "x" at the start of the word to the front of the list, but I can't be sure.
copy=words[:]
for i in copy:
i is generally used for numbers. Why not use "word"?
if i[0]!= str('x'):
Now, I don't know about you, but Python knows that 'x' is a string! :P
copy.remove(i)
copy=sorted(copy, reverse=True)
Urgh. Please don't edit your iterables while you're using them to iterate. How about using using a different variable, like one named "result"?
for i in words:
if i[0]==str('x'):
words.remove(i)
words=sorted(words)
Same applies here - and what's more, is that you can use result here!
print(copy+words)
Methods should do one of two things - edit a state (in a class) or return something. This does neither - how about returning the result, so you can use it in future?
If I were going to do this so that it was more readable and maintainable, I would do something like -
def move_words_starting_with_x_to_front(words):
words = sorted(words)
result = []
for word in words:
if word[0]=='x':
result.append(word)
else:
result.extend([word for word in words if word not in result])
return result
Obviously, not the shortest, nor does it have the shortest method name, but you sure know what it's going to do and how ;) I would personally extend it again, making it work for any character, or multiple characters, or directly on a sentence.