Actually, what you report getting is not what you are really getting. You
*should* be getting seven lines of the sort you mention. I assume you are.
But beyond that, it's behaving exactly as you should expect. For every
iteration of the loop, you are telling it to print the dictionary. It
appears to be doing that. Of course, it's not displaying the dictionary in
the *order* in which you *initialized* it. But that's because the
dictionary isn't really ordered like that. The dictionary is *not* a list.
It's a hash table. It's accessed by key, and not by an index.
You can't (shouldn't) treat the dictionary as being *ordered*. If you
really want a list of the stuff in the dictionary (and sometimes you might
want this), then you can get either the *list* of dictionary items
(fr.items()) or the *list* of dictionary values (fr.values()). These,
being lists, will be ordered. You can then either use them as-is or sort
them in one manner or another. I often do this kind of thing when I want
to create a list without duplicate items. I first create the dictionary
(which won't contain duplicates), and then create the list from its items.
···
--------------------------------------
Gary H. Merrill
Director and Principal Scientist, New Applications
Data Exploration Sciences
GlaxoSmithKline Inc.
(919) 483-8456
Thanks all of you. I knew that dictionary is not ordered but as you rightly assumed I didn't quite understand what should I expect from it. I am using lists with tuples in it now. I am writing app that should help me with frequency count, ranks etc. in text for linguistics and I am learning programming too
on the go.
Sorry again for posting this here and thanks again
Petr
···
gary.h.merrill@gsk.com wrote:
Actually, what you report getting is not what you are really getting. You
*should* be getting seven lines of the sort you mention. I assume you are.
But beyond that, it's behaving exactly as you should expect. For every
iteration of the loop, you are telling it to print the dictionary. It
appears to be doing that. Of course, it's not displaying the dictionary in
the *order* in which you *initialized* it. But that's because the
dictionary isn't really ordered like that. The dictionary is *not* a list.
It's a hash table. It's accessed by key, and not by an index.
You can't (shouldn't) treat the dictionary as being *ordered*. If you
really want a list of the stuff in the dictionary (and sometimes you might
want this), then you can get either the *list* of dictionary items
(fr.items()) or the *list* of dictionary values (fr.values()). These,
being lists, will be ordered. You can then either use them as-is or sort
them in one manner or another. I often do this kind of thing when I want
to create a list without duplicate items. I first create the dictionary
(which won't contain duplicates), and then create the list from its items.
--------------------------------------
Gary H. Merrill
Director and Principal Scientist, New Applications
Data Exploration Sciences
GlaxoSmithKline Inc.
(919) 483-8456
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
.
Hi there...
Given the task that you have (linguistics-related, with frequencies, etc.),
you should REALLY check out the following resource, it's fantastic (I've
used it for my programming assignments in my NLP courses):
Cheers,
Fred.
···
On 4/11/04 7:33 AM, "Petr ·imon" <sim@klubko.net> wrote:
Thanks all of you. I knew that dictionary is not ordered but as you
rightly assumed I didn't quite understand what should I expect from it.
I am using lists with tuples in it now. I am writing app that should
help me with frequency count, ranks etc. in text for linguistics and I
am learning programming too
on the go.
Sorry again for posting this here and thanks again
Petr