Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Best way to convert dictionary in string and remove quotes (" or ') around values

I have some dictionary of form:

Test = {'∧I': '([A, B] ⊦ ("A"∧B))', '∧E 1': "([(A∧B)] ⊦ 'A')", '∧E 2': '([(A∧B)] ⊦ B)'}

is their a simple way to convert it into some string without the ” around the values, means:

{'∧I': '([A, B] ⊦ ("A"∧B))', '∧E 1': ([(A∧B)] ⊦ A), '∧E 2': ([(A∧B)] ⊦ B)}

The problem with:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

str1 = f'{Test}'.replace('"','')

itself is that the dictionary itself uses " or ‘ inside some strings.

I posted some similar post with lists. But unfortunately its a little bit difficult to transfer it on dictionaries.

>Solution :

str_ = "{" + ", ".join([f"{k}: {v}" for k, v in Test.items()]) + "}"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading