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 9216183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:21:45+00:00 2026-06-18T02:21:45+00:00

Dictionary keeps the order correctly when there are around 1,2 or 3 elements only

  • 0

Dictionary keeps the order correctly when there are around 1,2 or 3 elements only

>>> a = ["dorian", "strawberry", "apple"]
>>> b = ["sweet", "delicious", "tasty"]
>>> c = dict(zip(a, b))
>>> c
{'dorian': 'sweet', 'strawberry': 'delicious', 'apple': 'tasty'}

But when there are over 3 elements, the order is broken

>>> a = ["dorian", "strawberry", "apple", "coconut"]
>>> b = ["sweet", "delicious", "tasty", "yum"]
>>> c = dict(zip(a, b))
>>> c
{'strawberry': 'delicious', 'coconut': 'yum', 'dorian': 'sweet', 'apple': 'tasty'}

Could anyone please explain why it happens that way ? thanks

  • 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-06-18T02:21:46+00:00Added an answer on June 18, 2026 at 2:21 am

    Python dictionaries don’t maintain any order, you should use OrderedDict for that.

    In [7]: from collections import OrderedDict as od
    
    In [8]: a = ["dorian", "strawberry", "apple"]
    
    In [9]: b = ["sweet", "delicious", "tasty"]
    
    In [10]: dic=od(zip(a,b))
    
    In [11]: dic
    Out[11]: OrderedDict([('dorian', 'sweet'), ('strawberry', 'delicious'), ('apple', 'tasty')])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a dictionary with 10 arrays and each array got 20 elements. How
I have this CacheManager class which keeps a static dictionary with all sorts of
Given a resource dictionary loading some static resources into memory - is there any
Possible Duplicate: Python dictionary, keep keys/values in same order as declared I'm going through
Possible Duplicate: Python dictionary, keep keys/values in same order as declared If I have
I am binding a Dictionary to a ComboBox which keeps the Enum values. To
I am using this var ordered = dictionary.Keys.OrderBy(x => x); to order a dictionary.
I have one Dictionary and added some elements on it.for example, Dictionary<string, string> d
Dictionary cannot have two values with same key. please tell which logic/algorithm being used
Resource dictionary 03-11-2010 10:56 AM | I have two different projects. I linked a

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.