Cindy -- If you read the Python documentation, you will see that a dictionary is stored with its elements in an un-specified (and therefore unpredictable) order. When the dictionary is created, the order in which the values were specified IS NOT PRESERVED. There are numerous references to this both in the Python documentation and other web resources. Try doing a google search on 'python dictionary key order' and you will see what I mean.
If you want the values to print out in some specified order, I can think of two ways to do that: 1. Keep another data item -- an array (which *does* preserve order) of key-names, and use that as the value of the 'in' attribute of the <iterate> element. 2. If you simply want them in alphabetical order or something like that, you could add code to get the keys into a list, sort that list, and then use the sorted list as the value to iterate over. --------------------------------------------------------------------------------------- Joe Veilleux IBM/Lotus Domino Server Quality Engineering 550 King Street Littleton MA 01460 Email: joeveill...@us.ibm.com Cindy Zhu <c...@fekete.com> To 10/25/2011 03:50 "staf-users@lists.sourceforge.net" PM <staf-users@lists.sourceforge.net> cc Subject [staf-users] Iterating a dictionary in a STAX job Hi, I have the following STAX job to iterate a dictionary and print out the keys in the dictionary. <script> testsWin = {'Harmony':0,'DeclinePlus':0, 'Harmony1':0, 'RTA':0} </script> <defaultcall function="main" /> <function name="main" scope="local"> <sequence> <iterate var="test" in="testsWin.keys()"> <log message="1">'test=%s' % test</log> </iterate> </sequence> </function> The log message shows in this order: Harmony1, DeclinePlus, RTA, Harmony. Is there a way to make the print out(message) has the same key order as that in variable testsWin? Thanks, Cindy ------------------------------------------------------------------------------ The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev _______________________________________________ staf-users mailing list staf-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/staf-users
<<inline: graycol.gif>>
<<inline: pic19436.gif>>
<<inline: ecblank.gif>>
------------------------------------------------------------------------------ The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________ staf-users mailing list staf-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/staf-users