dictionary - How to decode a python unicode list of dictionaries? -
i have form variable returns list of dictionaries looks this:
share_with = u'[{\"text\":\"leiaorgana@mycompany.org\"},{\"text\":\"yoda@mycompany.org\"},{\"text\":\"anakinskywalker@mycompany.org\"}] i'm trying use list comprehension list of email address backslashes throwing off.
share_with = [item item['text'] in str(share_with)] but error is:
global name 'item' not defined how loop thru form variable can list looks this:
share_with = ['leiaorgana@mycompany.org','yoda@mycompany.org','anakinskywalker@mycompany.org']
what have similar json object.
so, have decode valid mapping read emails:
>>> share_with = u'[{\"text\":\"leiaorgana@mycompany.org\"},{\"text\":\"yoda@mycompany.org\"},{\"text\":\"anakinskywalker@mycompany.org\"}]' >>> >>> >>> import json >>> json.loads(share_with) [{'text': 'leiaorgana@mycompany.org'}, {'text': 'yoda@mycompany.org'}, {'text': 'anakinskywalker@mycompany.org'}] >>> l = json.loads(share_with) >>> >>> l [{'text': 'leiaorgana@mycompany.org'}, {'text': 'yoda@mycompany.org'}, {'text': 'anakinskywalker@mycompany.org'}] >>> >>> [item['text'] item in l] ['leiaorgana@mycompany.org', 'yoda@mycompany.org', 'anakinskywalker@mycompany.org']
Comments
Post a Comment