P
PRC
Hi folks,
I have a tuple of tuples, in the form--> ((code1, 'string1'),(code2,
'string2'),(code3, 'string3'),)
Codes are unique. A dict would probably be the best approach but this
is beyond my control.
Here is an example:
If I am given a value for the code I need to retrieve the string
representation. The value is guaranteed to be valid.
This is what I came up with...
It does the job, I was just curious if there was a better way to do
it.
I have a tuple of tuples, in the form--> ((code1, 'string1'),(code2,
'string2'),(code3, 'string3'),)
Codes are unique. A dict would probably be the best approach but this
is beyond my control.
Here is an example:
If I am given a value for the code I need to retrieve the string
representation. The value is guaranteed to be valid.
This is what I came up with...
'dog'value=1
[ pet for code, pet in pets if value==code ][0]
It does the job, I was just curious if there was a better way to do
it.