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 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 CreateGUI(): WinCreate=Toplevel(master) WinCreate.attributes(-toolwindow,1) WinCreate.resizable(0,0) WinCreate.transient(master) WinCreate.grab_set() sideframe=Frame(WinCreate,bd=2,relief=GROOVE) Label(WinCreate,text= logbook ,fg=White,bg=#3b5998,font=(RoyalBavarian,20)).pack(side=TOP,fill=X) Label(sideframe,text=Name: ,fg=Black,font=(Tahoma,12)).grid(row=0,column=0,sticky=E) Label(sideframe,text=Age:
def plural(value, string) #{value} #{value.abs == 1 ? string.singularize : string.pluralize} end If not,
def ExtractViewState(string): m = re.match(__viewstate[^>]+value=\\(\?<Value>[^\]*\), string, re.IGNORECASE) return m.group(0) I think I'm missing something,
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 tong_thoigian (self,kr,uid,ids,context={}): obj=self.browse(kr,uid,ids,context=context)[0] kr.execute('''select name,giolam from x_giolam where name=%s'''%(obj.ma_luong)) kq=kr.fetchall() tong=0.00000 for i
def __init__(self, maximum, start=0, step=1): Sets the maximum, start, and step try: self.maximum =
def foo (): x = re.compile('^abc') foo2(x) def foo2(x): How do I get x
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def partial(template, *args) options = args.extract_options! options.merge!(:layout => false) if collection = options.delete(:collection) then

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.