0
s = problem.getSuccessors(currNode)
 print s
 child = dict((t[0], t[1:]) for t in s)
 print child
output of s = [((5, 4), 'South', 1), ((4, 5), 'West', 1)]
output of child = {(4, 5): ('West', 1), (5, 4): ('South', 1)}

Why the order has been changed?? 5,4 should be at first position and ( 4, 5) at 2nd position of child dict.

And how do I can put 1 more value for the key?

here my key is (5,4) and its values is south and 1. Now I want to have its parent node also as its value so that when I use the key[1]- it shud give me south, 1 and parent node

since "s" contains only 2 things,south and 1. so it is making only 2 values of the key. i need 1 more . what are the commands?

asked Jul 17, 2010 at 6:41
1

2 Answers 2

10

(1) In Python dictionaries are unordered. Use an OrderedDict (available since Python 2.7 and 3.1) if you need to maintain the insertion order.

(2) I don't know what you mean by "parent node".

answered Jul 17, 2010 at 6:43
Sign up to request clarification or add additional context in comments.

Comments

3

Dictionaries do not preserve key order.

You would need to use an ordered dict substitute.

answered Jul 17, 2010 at 6:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.