[Tutor] string list in alphabetical!

Sammy Cornet corsam28 at hotmail.com
Mon Oct 21 16:40:11 CEST 2013


I appreciate your help and advices in concern of my challenge. In fact, I'm confuse because I was sent a lot of lesson in comparison to what I usually have for each week. I will try it the you told me. Think you for all of your email.


On Oct 21, 2013, at 4:08, "Sammy Cornet" <corsam28 at hotmail.com> wrote:

> Thank you for help Steven! I intend to correct it. But also I would like to know if I wrote the correctly in order to the output that I'm looking for?
> 
> 
> 
> On Oct 20, 2013, at 19:22, "Sammy Cornet" <corsam28 at hotmail.com> wrote:
> 
>> Hello!
>> 
>> I'm using python 2.7.5 version and I'm trying to write a program related to a file named unsorted_fruits.txt contains a list of 26 fruits, each one with a name that begins with a different letter of the alphabet. My program's goal is to read in the fruits from the file unsorted_fruits.txt and writes them out in alphabetical order to a file named sorted_fruits.txt while I'm using while loop
>> 
>> For this assignment you must incorporate the use of a list, for loop and / or while loop.
>> 
>> so here is what I have on my script:
>> 
>> 
>> 
>> infile = open('Desktop/unsorted_fruits.docx' ,"r")
>> 
>> outfile = open('Desktop/sorted_fruits.docx', 'w')
>> 
>> 
>> 
>> def find():
>> 
>>     index = 0
>> 
>>     while index < 26:
>> 
>>         list < 26
>> 
>>         list = ["a", "b", "c", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n" "o", "p", "q", "r", "s", "t", "u", "v", "w", "z", "y", "z"]
>> 
>>         if index[0] == list[0]:
>> 
>>             infile = list + 1
>> 
>>             print infile
>> 
>>         index += 1
>> 
>>     infile.close() 
>> 
>>     outfile.close() 
>> 
>> 
>> And here is my output:
>> 
>> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
>> Type "copyright", "credits" or "license()" for more information.
>> >>> ================================ RESTART ================================
>> >>> 
>> 
>> Traceback (most recent call last):
>>   File "F:/7.real.py", line 1, in <module>
>>     infile = open('Desktop/unsorted_fruits.docx' ,"r")
>> IOError: [Errno 2] No such file or directory: 'Desktop/unsorted_fruits.docx'
>> >>> 
>> 
>> 
>> I'm not sure if I write the program correctly, but I can't get my file wich is on my desktop to the program. CAn someone help me please?
>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131021/62d534ee/attachment.html>
-------------- next part --------------
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list