Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 202853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:19:35+00:00 2026-05-11T17:19:35+00:00

When you call dict.values() the order of the returned items is dependent on the

  • 0

When you call dict.values() the order of the returned items is dependent on the has value of the keys. This seems to be very consistent in all versions of cPython, however the python manual for dict simply states that the ordering is “arbitrary”.

I remember reading somewhere that there is actually a PEP which specifically states the expected ordering of the items() and values() methods.

FYI, if this behavior is indeed a guaranteed behavior of a class I am working on I could greatly simplify and speed up a class I am working on. On the other hand if this is merely an accidental and undocumented feature of cPython then it’s probably best not to trust it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:19:35+00:00Added an answer on May 11, 2026 at 5:19 pm

    I suppose PEP-3106 is as close as it gets:

    The specification implies that the order in which items are returned by
    .keys(), .values() and .items() is the
    same (just as it was in Python 2.x),
    because the order is all derived from
    the dict iterator (which is presumably
    arbitrary but stable as long as a dict
    isn’t modified). This can be expressed
    by the following invariant:

    list(d.items()) == list(zip(d.keys(),
    d.values()))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Python dictionary, keep keys/values in same order as declared I'm going through
I call a function like this: call_facebook(103138046395999, samåkning.se, http://www.facebook.com/samakning, page); call_facebook(16089699074, Jag ska köra
I call this function from with my code-behind: DeleteFile(Server.MapPath(/) + sitemap_index.xml) Public Shared Function
I call this a flash meeting, but maybe there is another more appropriate name.
I'm adding Annotations to a map, and in order to call them I need
I currently have a structure that is a dict: each value is a list
class warehouse: def __init__(self): self.A={} self.B={} self.racks={'A':self.initialize(self.A),'B':self.initialize(self.B)} def initialize(self,rack): shelf = dict([ (items,0) for
I'd like to convert the result of a Tweepy api.trends_location(woeid) call to a dict
I have formed a dictionary with 2 keys assigning to a single dictionary value,
I am trying to print the value of a func.count() call, but I'm having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.