Dejell Dejell - 1 year ago 120
Python Question

set value as dictionary with list python

I am trying to create the following json in python:

targeting_json = {
u"publisher_platforms": [u"facebook"],
u"geo_locations": {
{u"countries": [u"US"]}
u"app_install_state": u"not_installed",
u"user_os": [u"iOS_ver_8.1_and_above"],
u"age_min": 13,
u"age_max": 65

However it fails with the error:
unhashable type: 'dict'
on the lines

u"geo_locations": {
{u"countries": [u"US"]}

How can I set as a value - a dictionary with list?

Answer Source

You have

u"geo_locations": {
                {u"countries": [u"US"]}

But it should be

u"geo_locations": {u"countries": [u"US"]},

Outer {} is creating set and sets are unhashable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download