Python Forum

Full Version: Dictionaries and Variables?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have watched about 6 videos and tried to find documentation concerning this to no avail. Is there a way to read a value from a list into a variable and place that variable in a dictionary representing that value? What I'm trying to say is, I'm trying to read a line from a csv file, then select one of the fields from that line and put it in a dictionary as a value.

Thank you
You can put the data within the variable into a dictionary (not the variable itself).

l = ['colA', 'colB', 'colC', 'colD', 'colE']
one_value = l[2]
d = {'myvalue': one_value}
print(d)
Output:
{'myvalue': 'colC'}
Thank you so much.