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

  • Home
  • SEARCH
  • 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 620623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:47:02+00:00 2026-05-13T18:47:02+00:00

def createNode(doc_, **param_): cache = {‘p’:’property’,’l’:’label’,’td’:’totalDelay’,’rd’:’routeDelay’,’ld’:’logicDelay’} for index in param_: newIndex = cache[index] value

  • 0


def createNode(doc_, **param_):
cache = {‘p’:’property’,’l’:’label’,’td’:’totalDelay’,’rd’:’routeDelay’,’ld’:’logicDelay’}
for index in param_:
newIndex = cache[index]
value = param_[index]
print newIndex, ‘=’, value

doc = 10
createNode(doc, p=’path’, l=’ifft4k_radix4_noUnolling_core.vi’, td=’3.0′, ld=’1.0′, rd=’2.0′)

Running this code on Python 2.6 gives me the following result.


routeDelay = 2.0
property = path
totalDelay = 3.0
logicDelay = 1.0
label = ifft4k_radix4_noUnolling_core.vi

I need to keep the order of the parameters, I mean, property comes first, then label until I get routeDelay last.

Q : What’s the way to keep the dictionary parameter order in Python?

  • 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-13T18:47:03+00:00Added an answer on May 13, 2026 at 6:47 pm

    I need to keep the order of the
    parameter, I mean, property comes
    first, then label until I get
    reouteDelay last.

    Then you’re simply doing things in the wrong order — no need for ordered dictionaries! Try, instead, a tuple of pairs for cache, as follows:

    def createNode(doc_, **param_):
        cache = ( ('p', 'property'), , ('l', 'label'), ('td', 'totalDelay'),
                  ('rd', 'routeDelay'), ('ld', 'logicDelay') )
        for index, newIndex in cache:
            if index not in param_:
                continue
            value = param_[index]
            print newIndex, '=', value
    

    This has exactly the same semantics as your version of createNode, plus the desired property of maintaining the order you wish, and performance is at least as good. By focusing on “keeping the dictionary ordered” you’re focusing on the wrong problem (as is the case, alas, for most cases where people reach for “ordered dictionaries”!-).

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

Sidebar

Related Questions

def set_attribute(attributes, name, value): for i, attribute in enumerate(attributes): if name in attribute: quote_char
def index @cellphones = Cellphone.all respond_to do |format| format.html # index.html.erb format.json { render
def [](index) case index when 0, -2: @x when 1, -1: @y when :x,
def initUI(self): self.columnconfigure(5, weight=1) self.rowconfigure(3, weight=1) self.search_label = Label(self, text='Keyword:') self.search_label.grid(row=0, column=0, padx=5) self.keywords
def remove_whitespaces(value): Remove all whitespaces p = re.compile(r'\s+') return p.sub(' ', value) The above
def ExtractViewState(string): m = re.match(__viewstate[^>]+value=\\(\?<Value>[^\]*\), string, re.IGNORECASE) return m.group(0) I think I'm missing something,
def doSomething(value) if (value.is_a?(Integer)) print value * 2 else print Error: Expected integer value
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
def self.jq_column_models COLUMN_NAME.collect {|x| {:name => x.to_s, :width => 80, :format => 'integer' if
def On_Instrumentation_StartAnimation(): Syntax : On_Instrumentation_StartAnimation() Purpose : Fired if the animation is started Parameters

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.