python - Convert OrderedDict to normal dict preserving order? -


how convert ordereddict normal dictionary while preserving same order?

the reason asking because when fetch data api, json string, in use json.loads(str) return dictionary. dictionary returned json.loads(...) out of order , randomly ordered. also, i've read ordereddict slow work want use regular dict in same order original json string.

slightly off-topic: there anyway convert json string dict using json.loads(...) while maintaining same order without using collections.ordereddict?

when convert ordereddict normal dict, can't guarantee ordering preserved, because dicts unordered. why ordereddict exists in first place.

it seems you're trying have cake , eat too, here. if want order of json string preserved, use answer question linked in comments load json string directly ordereddict. have deal whatever performance penalty carries (i don't know offhand penalty is. may neglible use-case.). if want best possible performance, use dict. it's going unordered.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -