> On Feb 13, 2017, at 12:34, SIJIA CHEN <schen...@wisc.edu> wrote:
> 
> I find out that the outcome for using .join() on a dictionary is totally 
> different than it using on list or string. for example,
> 
>>>> seq4 = {'hello':1,'good':2,'boy':3,'doiido':4}
>>>> print ':'.join(seq4)
>                  boy:good:doiido:hello
> So my question is why the outcome doesn't show sequentially as the same 
> sequence of the original seq4?  What pattern do those "keys" of the 
> dictionary in the outcome show ?

Dictionaries (in particular, their keys) are unordered.  You can not rely on 
them to be in a particular sequence.  The reason for this, from a practical 
perspective, is you are expected to ask for the specific key; you should not 
care about the ordering.

Lists, on the other hand, have a specific order by design so will always be in 
the order they were created.

What are you trying to do with join() on a dictionary in the first place?  Is 
there a specific outcome you are trying to get?  It’s unlikely that using join 
on a dictionary is what you actually want.

—
David Rock
da...@graniteweb.com




_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to