[Tutor] Tutor Digest, Vol 100, Issue 58
Mike Nickey
mnickey at gmail.com
Tue Jun 26 00:12:46 CEST 2012
>> The problem with this code is that it only gets the first word beginning
>> with x and the others remaisn on the original list, sorted at the end. I've
>> tested on terminal many parts of the code and it whas fine, but when I run
>> it complete, it does not work.
>>
>> Following is the solution of the problem. I can understand it, I just
>> can't understand why my code does not work.
>>
>> #############################
>> def front_x(words):
>> x_list = []
>> other_list = []
>> for w in words:
>> if w.startswith('x'):
>> x_list.append(w)
>> else:
>> other_list.append(w)
>> return sorted(x_list) + sorted(other_list)
>> ##############################
I did the same exercise so maybe I can assist here. From what I see, the line...
if w.startswith('x'): seems to be ineffective.
Try using the operator that checks for equality such as
if w[0] == 'x':
This will check the first of each word for 'x' and move it to the proper list.
You should be able to figure it out from here.
Good luck!
>>
>> To download all the exercises, access:
>> http://code.google.com/edu/languages/google-python-class/google-python-exercises.zip
>>
>>
>> Thank y'all.
>>
>>
>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/tutor/attachments/20120625/9059f044/attachment.html>
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 100, Issue 58
> **************************************
--
~MEN
More information about the Tutor
mailing list