-1
[
    {
      'address': 'f5f891c1009db80a4fabd7c329bbc58068c5796aef6c4547fbd155c775b946843b757d'
    },
    {
      'owner': '02876ba3dab1013b568e20a961522090b83e8ce0d3f797b2e795d445089db50767'
    },
    "{'name': 'f5f891c1006142efc3c6ea431f2c5d8bd794cbe9a1695f6112586aad2d9e799e535f6b', 'quantity': '22', 'has_link': True, 'address': 'f5f891c1006142efc3c6ea431f2c5d8bd794cbe9a1695f6112586aad2d9e799e535f6b'}" ]

The last value is a string of dictionary which is

"{'name': 'f5f891c1006142efc3c6ea431f2c5d8bd794cbe9a1695f6112586aad2d9e799e535f6b', 'quantity': '22', 'has_link': True, 'address': 'f5f891c1006142efc3c6ea431f2c5d8bd794cbe9a1695f6112586aad2d9e799e535f6b'}" 

how can I get it in this format, the double quotation completely remove

{'name': 'f5f891c1006142efc3c6ea431f2c5d8bd794cbe9a1695f6112586aad2d9e799e535f6b', 'quantity': '22', 'has_link': True, 'address': 'f5f891c1006142efc3c6ea431f2c5d8bd794cbe9a1695f6112586aad2d9e799e535f6b'}
Lamin L Janneh
  • 75
  • 1
  • 10

1 Answers1

2

Use ast.literal_eval:

import ast

d = "{'name': 'f5f891c1006142efc3c6ea431f2c5d8bd794cbe9a1695f6112586aad2d9e799e535f6b', 'quantity': '22', 'has_link': True, 'address': 'f5f891c1006142efc3c6ea431f2c5d8bd794cbe9a1695f6112586aad2d9e799e535f6b'}"

print(ast.literal_eval(d))
Austin
  • 25,759
  • 4
  • 25
  • 48