Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )

HenHanna HenHanna at devnull.tb
Fri May 31 00:47:14 EDT 2024


          ;;;  Pls tell me about little tricks you use in Python or Lisp.


[('the', 36225), ('and', 17551), ('of', 16759), ('i', 16696), ('a', 
15816), ('to', 15722), ('that', 11252), ('in', 10743), ('it', 10687)]

((the 36225) (and 17551) (of 16759) (i 16696) (a 15816) (to 15722) (that 
11252) (in 10743) (it 10687))


i think the latter is easier-to-read, so i use this code
                                                        (by Peter Norvig)

def lispstr(exp):
            # "Convert a Python object back into a Lisp-readable string."
     if isinstance(exp, list):
         return '(' + ' '.join(map(lispstr, exp)) + ')'
     else:
         return str(exp)

def Lprint(x): print(lispstr(x))


More information about the Python-list mailing list