0

I have these two lines:

a=[0,10,3,5,7,8]
size = 6;
{a[idx] for idx in range(0,size)}

And the output looks like:

{0, 3, 5, 7, 8, 10}

Which is sorted, I am using these to visualize all the values in a dictionary, do you know why is this happening, and if is just default configuration, do you know how to visualize all the values for a given key in a dictionary with multiple keys. e.g visualize all values for key_2 in x[key_1][key_2]

Leon palafox
  • 2,675
  • 6
  • 27
  • 35
  • 1
    That is not a list comprehension; it is a set comprehension. Moreover, the order of sets is undefined which means that it could be anything (including ordered). –  Jul 18 '14 at 18:52
  • So that's not a list comprehension, it's a set comprehension. I'm not sure what it is you're trying to accomplish, exactly. Can you post expected output? – Adam Smith Jul 18 '14 at 18:52
  • 1
    You are not creating a list. that is a set. set's are unsorted (meaning they don't keep track of the order stuff gets put into them, python seems to sort numbers). use "[" instead of "{" – Daniel Kogan Jul 18 '14 at 18:53
  • Thanks, I was going crazy, it was a part f code someone sent to me, and I never noticed the { instead of the [ in the list comprehension – Leon palafox Jul 18 '14 at 19:08

0 Answers0