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?

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".

3

Dictionaries do not preserve key order.

You would need to use an ordered dict substitute.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.