Hrvoje Niksic writes:
> Ben Finney writes:
>
> > Tim Chase writes:
> >> Does this "never trust it" hold even for two consecutive iterations
> >> over an unchanged dict? I didn't see anything in the docs[1] to make
> >> such a claim,
> >
> > Exactly.
>
> This is false. The docs say:
>
> If
Ben Finney writes:
> Tim Chase writes:
>
>> On 11/03/11 16:36, Terry Reedy wrote:
>> > CPython iterates (and prints) dict items in their arbitrary internal
>> > hash table order, which depends on the number and entry order of the
>> > items. It is a bug to depend on that arbitrary order in any w
Tim Chase writes:
> On 11/03/11 16:36, Terry Reedy wrote:
> > CPython iterates (and prints) dict items in their arbitrary internal
> > hash table order, which depends on the number and entry order of the
> > items. It is a bug to depend on that arbitrary order in any way.
>
> Does this "never tru
On Fri, Nov 4, 2011 at 10:01 AM, Tim Chase
wrote:
> list1 = list(d.iterkeys())
> list2 = list(d.iterkeys())
> assert list1 == list2
>
There is such a guarantee in Python 2. From
http://docs.python.org/library/stdtypes.html:
"If items(), keys(), values(), iteritems(), iterkeys(), and
itervalues
On 11/03/11 16:36, Terry Reedy wrote:
> Is there a way to not sort them and leave the order as is?
CPython iterates (and prints) dict items in their arbitrary internal
hash table order, which depends on the number and entry order of the
items. It is a bug to depend on that arbitrary order in
On 11/3/2011 2:46 PM, Scott Ware wrote:
Python newbie here. So, when creating dictionaries, I am noticing
that each time I print it out, that its not in the same order as when
I typed it in. They seem to be getting sorted somehow.
No, the entries are not being sorted at all.
> Is there a way t
Moreover, for on-the-fly ordering you can consider to use sorted() on
yourdict.keys(), like:
for k in sorted(yourdict.keys()):
print k, yourdict[k]
I think it has no side effects, except that the orderering can be slow on huge
data sets, and that you need to call it every time after updatin
Note that there are a number of recipes available for free online, and
if you are using a newer version of Python (2.7 or higher), the
collections module includes an OrderedDict class
(http://docs.python.org/library/collections.html#collections.OrderedDict
- this also include a library for Python 2
Great! Thanks, John for the quick response!
--
http://mail.python.org/mailman/listinfo/python-list
In <16245908.783.1320346014867.JavaMail.geo-discussion-forums@yqhd1> Scott Ware
writes:
> Python newbie here. So, when creating dictionaries, I am noticing that
> each time I print it out, that its not in the same order as when I typed
> it in. They seem to be getting sorted somehow. Is there a
Python newbie here. So, when creating dictionaries, I am noticing that each
time I print it out, that its not in the same order as when I typed it in. They
seem to be getting sorted somehow. Is there a way to not sort them and leave
the order as is?
Thanks!
--
http://mail.python.org/mailman/li
Sam Loxton wrote:
> I am fairly new to the python language and am trying to sort a nested
> Dictionary of a Dictionary which I wish to sort by value. The dictionary
> does not have to be restructured as I only need it sorted in this way
> for printing purposes.
>
> The following is an example of
Hi,
I am fairly new to the python language and am trying to sort a nested
Dictionary of a Dictionary which I wish to sort by value. The dictionary
does not have to be restructured as I only need it sorted in this way
for printing purposes.
The following is an example of my Dictionary printed w
On 17 Sep 2005 11:01:41 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote:
>Bengt Richter wrote:
>
>> or tell sorted what to do ;-)
>>
>> >>> original= {
>> ... 'hello':135,
>> ... 'goodbye':30,
>> ... 'lucy':4,
>> ... 'sky':55,
>> ... 'diamonds':239843,
>> ... 'yesterday':4 }
>> >>> list(sorted(
Bengt Richter wrote:
> or tell sorted what to do ;-)
>
> >>> original= {
> ... 'hello':135,
> ... 'goodbye':30,
> ... 'lucy':4,
> ... 'sky':55,
> ... 'diamonds':239843,
> ... 'yesterday':4 }
> >>> list(sorted(original.iteritems(), None, lambda t:t[1], True))
> [('diamonds', 239843), ('hell
On Fri, 16 Sep 2005 21:42:40 +0200, Irmen de Jong <[EMAIL PROTECTED]> wrote:
>JerryB wrote:
>> Hi,
>> I have a dictionary for counting ocurrences of strings in a document.
>> The dictionary looks like this:
>>
>> 'hello':135
>> 'goodbye':30
>> 'lucy':4
>> 'sky':55
>> 'diamonds':239843
>> 'yesterd
You can't sort dictionaries (as implemented by hash tables), they are
unordered data types, so by definition there's no way to force an order
on them.
http://en.wikipedia.org/wiki/Hash_tables
--
http://mail.python.org/mailman/listinfo/python-list
JerryB wrote:
> Hi,
> I have a dictionary for counting ocurrences of strings in a document.
> The dictionary looks like this:
>
> 'hello':135
> 'goodbye':30
> 'lucy':4
> 'sky':55
> 'diamonds':239843
> 'yesterday':4
>
> I want to print the dictionary so I see most common words first:
>
> 'diamond
Hi,
I have a dictionary for counting ocurrences of strings in a document.
The dictionary looks like this:
'hello':135
'goodbye':30
'lucy':4
'sky':55
'diamonds':239843
'yesterday':4
I want to print the dictionary so I see most common words first:
'diamonds':239843
'hello':135
'sky':55
'goodbye':3
"Rakesh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> This gets a list sorted by the keys.
That is all you *can* get (with the list keys being the dict values).
> How would I get a revised dictionary sorted by its values.
You can't. A dictionary is not sorted. The print orde
Another alternative:
d1 = {'a':4,'b':5,'c':1,'d':2,'e':3}
il=[(v,k) for k,v in d1.items()]
il.sort()
--
http://mail.python.org/mailman/listinfo/python-list
On 31 Mar 2005 22:40:53 -0800, "Rakesh" <[EMAIL PROTECTED]>
wrote:
>Hi,
> For a particular problem of mine, I want to sort pairs
>by its value.
>
>Eg:
>
>Input:
>
>A, 4
>B, 5
>C, 1
>D, 2
>E, 3
>
>I would like the output to be:
>
>C
>D
>E
>A
>B
>
>i.e. I would like to get the keys in the sorted o
Rakesh wrote:
Hi,
For a particular problem of mine, I want to sort pairs
by its value.
Eg:
Input:
A, 4
B, 5
C, 1
D, 2
E, 3
I would like the output to be:
C
D
E
A
B
the following code does that:
>>> d1 = {'a':4,'b':5,'c':1,'d':2,'e':3}
>>> i1 = [ (d1[i], i) for i in d1.keys() ]
>>> i1.sort()
>>
hi,
assuming your key-value relationship is one-to-one then as a simple first
pass you can simply initialize d1={} and for i in d.keys(): d1[d[i]] = i
and pass d1 to your sortedDictValue3 function, no?
thanks,
Vikram
On 31 Mar 2005, Rakesh wrote:
> Hi,
> For a partic
Hi,
For a particular problem of mine, I want to sort pairs
by its value.
Eg:
Input:
A, 4
B, 5
C, 1
D, 2
E, 3
I would like the output to be:
C
D
E
A
B
i.e. I would like to get the keys in the sorted order of values.
I did google around a little bit. One solution to a similar problem
sugges
25 matches
Mail list logo