Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > dict.keys() and dict.values() are always the same order, is it?

Reply
Thread Tools

dict.keys() and dict.values() are always the same order, is it?

 
 
Menghan Zheng
Guest
Posts: n/a
 
      04-20-2010
Hello!

Is it assured the following statement is always True?
If it is always True, in which version, python2.x or python3.x?

>>> a = dict()

....
>>> assert(a.values == [a[k] for k in a.keys()])

--> ?


Menghan Zheng
 
Reply With Quote
 
 
 
 
alex23
Guest
Posts: n/a
 
      04-20-2010
On Apr 20, 1:03*pm, Menghan Zheng <(E-Mail Removed)> wrote:
> Is it assured the following statement is always True?
> If it is always True, in which version, python2.x or python3.x?


I believe its an implementation detail and should not be relied on. If
you need consistent ordering, use an OrderedDict[1] or sort() the
lists beforehand.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: dict.keys() and dict.values() are always the same order, is it? Cameron Simpson Python 6 04-21-2010 04:37 AM
I thought ASP.NET was always the same version as the installed Framework? PJ6 ASP .Net 4 08-30-2005 06:45 PM
SQL query gets random image, but browser always loads same one Haydnw ASP .Net 5 09-25-2004 05:35 PM
Trying to create a CSS box that is always is always the width of an image placed inside it (and no wider) Deryck HTML 4 06-22-2004 08:25 PM
why did this hashmap always returned the same object? ravi mannan Java 2 11-23-2003 10:10 PM



Advertisments