0

I have a list of dictionaries of which when i want to print the list index element of a key in the dictionary, the output is the index of the character and not the element.

reader = csv.DictReader(mycsvfile, fieldnames)
        for row in reader:
            print row

example output:

{'name':'tom','numbers':"['1','2','3']"} #row

print row['numbers']

['1',2','3'] #correct

print row['numbers'][0]

[           #wrong

How do i convert row['numbers'] to a list?

jxn
  • 7,685
  • 28
  • 90
  • 172

1 Answers1

0

That's okay:

>>> row = {'name':'tom','numbers':['1','2','3']}
>>> row['numbers']
['1', '2', '3']
>>> row['numbers'][0]
'1'
>>> row['numbers'][1]
'2'
>>> row['numbers'][2]
'3'
>>> 
EbraHim
  • 2,279
  • 2
  • 16
  • 28