|
|
Kevin Wampler wrote:
> Interesting. So, to make sure I understand correctly if dicts in python
> were to operate like this then:
>
> D = dict()
> d["a"] = "foo"
> d["b"] = "bar"
> d["c"] = "baz"
>
> would give me {"a":"foo", "b":"bar", "c":"baz"} where the order matters
> so D[1] gives "bar"?
No, because key 1 isn't set to any value. However, if you iterate over the
array, you'll get items a, b, c, in that order.
> If so, then what happens in the following case:
>
> D = dict()
> d[3] = "foo"
> d[2] = "bar"
> d[1] = "baz"
Then d[3] is "foo", but if you iterate, it will be the first item to show
up.
Post a reply to this message
|
|