Re: Problem loading a file of words

2005-07-25 Thread Peter Hansen
teoryn wrote: > I changed to using line = line.strip() instead of line = line [:-1] in > the original and it it worked. Just to be clear, these don't do nearly the same thing in general, though in your specific case they might appear similar. The line[:-1] idiom says 'return a string which is a

Re: Problem loading a file of words

2005-07-25 Thread teoryn
I changed to using line = line.strip() instead of line = line [:-1] in the original and it it worked. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem loading a file of words

2005-07-25 Thread teoryn
I was just happy that it worked, but was still curious as to why it didn't before. Thanks for the idea, I'll look into it and see if this is the case. Thanks, Kevin -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem loading a file of words

2005-07-25 Thread Peter Otten
teoryn wrote: > I'm still lost as to why my old code would only work for the small > file, and another interesting note is that with the larger file, it > would only write "zzz for zzz" (or whatever each word was) instead of > "Created key zzz for zzz". However, it works now, so I'm happy. Happy

Re: Problem loading a file of words

2005-07-25 Thread teoryn
Thanks to everyone for all the help! Here's the (at least for now) final script, although note I'm using 2.3.5, not 2.4, so I can't use some of the tips that were given. #!/usr/bin/python # Filename: unscram.py def sort_string(word): '''Returns word in lowercase sorted alphabetically'''

Re: Problem loading a file of words

2005-07-25 Thread Steven D'Aprano
On Sun, 24 Jul 2005 20:44:08 -0700, teoryn wrote: > I've been spending today learning python and as an exercise I've ported > a program I wrote in java that unscrambles a word. Before describing > the problem, here's the code: > > *--beginning of file--* > #!/usr/bin/python > # Filename: unscram.

Re: Problem loading a file of words

2005-07-24 Thread Peter Otten
teoryn wrote: > I've been spending today learning python and as an exercise I've ported > a program I wrote in java that unscrambles a word. Before describing > the problem, here's the code: > line = str.lower(line[:-1]) # convert to lowercase just in case > have to add exceptions later)

Re: Problem loading a file of words

2005-07-24 Thread Devan L
Robert Kern wrote: > That's definitely not the kind of dictionary that he wants. > > -- > Robert Kern > [EMAIL PROTECTED] > > "In the fields of hell where the grass grows high > Are the graves of dreams allowed to die." >-- Richard Harter Oh, I missed the part where he put values in a list

Re: Problem loading a file of words

2005-07-24 Thread Robert Kern
Devan L wrote: > Heh, it reminds me of the code I used to write. > > def sort_string(word): > return ''.join(sorted(list(word.lower( > f = open('dictionary.txt','r') > lines = [line.rstrip('\n') for line in f.readlines()] > f.close() > dictionary = dict((sort_string(line),line) for line i

Re: Problem loading a file of words

2005-07-24 Thread Terrance N. Phillip
Kevin, I'm pretty new to Python too. I'm not sure why you're seeing this problem... is it possible that this is an "out-by-one" error? Is zymotechnics the *last* word in dictionary.txt? Try this slightly simplified version of your program and see if you have the same problem def sor

Re: Problem loading a file of words

2005-07-24 Thread Robert Kern
teoryn wrote: > I've been spending today learning python and as an exercise I've ported > a program I wrote in java that unscrambles a word. Before describing > the problem, here's the code: > > *--beginning of file--* > #!/usr/bin/python > # Filename: unscram.py > > def sort_string(word): >

Re: Problem loading a file of words

2005-07-24 Thread Devan L
teoryn wrote: > I've been spending today learning python and as an exercise I've ported > a program I wrote in java that unscrambles a word. Before describing > the problem, here's the code: > > *--beginning of file--* > #!/usr/bin/python > # Filename: unscram.py > > def sort_string(word): >

Problem loading a file of words

2005-07-24 Thread teoryn
I've been spending today learning python and as an exercise I've ported a program I wrote in java that unscrambles a word. Before describing the problem, here's the code: *--beginning of file--* #!/usr/bin/python # Filename: unscram.py def sort_string(word): '''Returns word in lowercase s