[Tutor] Using contents of a document to change file names, (was Re: how to extract data only after a certain ...)

Josep M. Fontana josep.m.fontana at gmail.com
Tue Oct 12 19:52:24 CEST 2010

Thanks Chris and Alan,

OK, I see. Now that I managed to build the dictionary, I did a print to
confirm that indeed the dictionary was created and it had the intended
contents and I was surprised to see that the order of the items in it was
totally changed. So the text file from which the dictionary was created was
sorted in alphabetical order ('A-01,1334', 'A-02,1234',...'I-01,1334'...),
but when I print the dictionary, I get: {'I-02': '1399', 'I-01': '1374',
'D-09': '1524', 'I-07': '1399' .....}

I don't think this will be a problem for what I want to do next but I'm
curious to know why the order is all changed in a way that doesn't seem to
be very intuitive.

Josep M.

On Mon, Oct 11, 2010 at 2:23 PM, Christian Witts <cwitts at compuscan.co.za>wrote:

> <snip>
> What you should be doing is:
> fileNameCentury =
> open('/Volumes/DATA/Documents/workspace/GCA/CORPUS_TEXT_LATIN_1/FileNamesYears.txt',
> 'r')
> dct = {}
> for line in fileNameCentury: #File objects have built-in iteration
>    key, value = line.strip().split(',')
>    dct[key] = value
> <snip>

Hope that helps.

It did. A great deal! Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101012/67885012/attachment.html>

More information about the Tutor mailing list