Skip to content

How to convert between Clojure maps and Python dictionaries? #1196

Answered by ikappaki
wjke-nics asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @wjke-nics,

You can use the lisp->python to recursively convert Basilisp data structures into Python data structures,. These includes converting keyword keys into strings by default:

basilisp.user=> (lisp->py {:ten {:eleven 11}})
#py {"ten" #py {"eleven" 11}}

Use the py->lisp to recursively convert Python data structures into Basilisp data structures. These includes converting string keys into keywords by default:

basilisp.user=> (py->lisp #py {"twelve" #py {"thirteen" 13}})
{:twelve {:thirteen 13}}

In addition

You can use the #py {...} reader macro to define a Python Dictionary in Basilisp (see Data Readers):

basilisp.user=> #py {"six" 6}
#py {"six" 6}

Use the python/dict function to …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by wjke-nics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants