Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionaries and Variables?
#1
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
Reply
#2
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'}
Reply
#3
Thank you so much.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020