I have a dictionary with one key and two values and I want to set each value to a separate variable.
d= {'key' : ('value1, value2'), 'key2' : ('value3, value4'), 'key3' : ('value5, value6')}
I tried d[key][0] in the hope it would return "value1" but instead it return "v"
Any suggestions?
A better solution is to store your value as a two-tuple:
d = {'key' : ('value1', 'value2')}
That way you don't have to split every time you want to access the values.
Try something like this:
d = {'key' : 'value1, value2'}
list = d['key'].split(', ')
list[0] will be "value1" and list[1] will be "value2".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With