Sujet : Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python )
De : HenHanna (at) *nospam* devnull.tb (HenHanna)
Groupes : comp.lang.python comp.lang.lisp comp.lang.schemeDate : 31. May 2024, 05:47:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3bkoj$23bck$1@dont-email.me>
User-Agent : Mozilla Thunderbird
;;; 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))