I'm currently running into this error and I cannot find the issue. At first, I thought it was because in the transformed_data[2]
, there was only 1, but that doesn't seem to be the case.
ValueError: dictionary update sequence element #0 has length 1; 2 is required
My code:
print(transformed_data)
country =transformed_data[0]
continent = transformed_data[1]
transformed_data[2] = transformed_data[2].replace("''",'test')
print(dict(transformed_data[2])) # when I add dict it does the error.
print((transformed_data[2])) # without dict, no error.
shell without dict:
['Qatar', 'ASIA', '{2001: 41.215}', '{2001: 615000}']
{2001: 41.215}
['Cameroon', 'AFRICA', '{2001: 3.324}', '{2001: 16358000}']
{2001: 3.324}
['Democratic Republic of Congo', 'AFRICA', '{2006: 1.553}', '{2006: 56578000}']
{2006: 1.553}
['Bulgaria', 'EUROPE', '{2001: 48.923}', '{2001: 7931000}']
{2001: 48.923}
['Poland', 'EUROPE', '{2001: 306.696}', '{2001: 38489000}']
{2001: 306.696}
['Lesotho', 'AFRICA', "{1975: ''}", "{1975: '1161000'}"]
{1975: test}
['Albania', 'EUROPE', '{2002: 3.748}', '{2002: 3126000}']
{2002: 3.748}
['Colombia', 'SOUTH AMERICA', '{2001: 56.259}', '{2001: 39630000}']
{2001: 56.259}
['Pakistan', 'ASIA', '{2012: 166.33}', '{2012: 187280000}']
{2012: 166.33}
Shell with dict:
Exception raised:
Traceback (most recent call last):
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/doctest.py", line 1330, in __run
compileflags, 1), test.globs)
File "<doctest __main__.get_bar_co2_pc_by_continent[1]>", line 1, in <module>
get_bar_co2_pc_by_continent(d1, 2001)
File "/Users/bob/Desktop/python class/assignment/final/plot_data.py", line 33, in get_bar_co2_pc_by_continent
print(dict(transformed_data[2]))
ValueError: dictionary update sequence element #0 has length 1; 2 is required