Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting the 'nth' field from an adt.Product #57

Closed
rdaly525 opened this issue Jul 6, 2019 · 2 comments
Closed

getting the 'nth' field from an adt.Product #57

rdaly525 opened this issue Jul 6, 2019 · 2 comments
Assignees

Comments

@rdaly525
Copy link
Collaborator

rdaly525 commented Jul 6, 2019

It would be great if field_dict and value_dict in adt.Product were an OrderedDict. Alternatively, keeping a ordered list of field names would be sufficient.

@cdonovick, is there any ways to get the 'nth' field from a Product currently?

@cdonovick
Copy link
Collaborator

@rdaly525 all dicts are ordered in 3.7 and have been in CPython since 3.6. The nth fieldname is the nth key.

https://docs.python.org/3/library/stdtypes.html#typesmapping
"Dictionaries preserve insertion order. Note that updating a key does not affect the order. Keys added after deletion are inserted at the end. ... Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was an implementation detail of CPython from 3.6"

Also if you just want the nth field you can tuple index products.

@cdonovick cdonovick reopened this Jul 8, 2019
@cdonovick
Copy link
Collaborator

As the order should matter in comparison of field dicts I will switch to an OrderedDict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants