Hey guys,

Trying to learn python. Anyone have any idea why this prints score_value first?

ie this is the output
{'score_value': 3.0, 'score_type': 1}{'score_value': 3.0, 'score_type': 4}{'score_value': 3.0, 'score_type': 5}

scores_for_bulk = []
    for i in range(4):
      if not score[i] == 0:
        self.response.out.write({"score_type":SCORE_TYPES[types[i]], "score_value": score[i]})

Any help would be appreciated.

Recommended Answers

All 2 Replies

Because dictionaries have hashable values as keys. And so the keys are ordered by their hash.

Cheers and Happy coding

If you like things to keep in order, consider list or tuple instead of dictionary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.