0

Dict(ages) .. output is not in sequence. Can anyone explain..

ages = {"Dave": 24, "Mary": 42, "John": 58} print(type(ages)) print(dict(ages))

16th Mar 2017, 4:27 AM
Abin Singh R
Abin Singh R - avatar
4 Respostas
+ 6
Dictionaries are not ordered structures. You might get a different output order each time.
16th Mar 2017, 6:26 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
No, not to be predicted, it's done automatically behind the scenes. There are some tendencies in which Python structures dictionaries, but it's the kind of data series you can't rely on when it comes to ordering. Simply the question of ordering is irrelevant for dictionaries, they are not suited for order-dependent tasks. For this purpose you have lists or tuples. Or you may store a tuple as a key, where the first element is a number and the second is the actual key to be considered. And try to build ordering on that... (but this is a serious overwork, I think)
16th Mar 2017, 7:54 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
each time when execution.. how to predict those outputs.. Is any format ? it follows
16th Mar 2017, 7:41 AM
Abin Singh R
Abin Singh R - avatar
0
ya thanks for your answer's
16th Mar 2017, 8:25 AM
Abin Singh R
Abin Singh R - avatar