What is the Hy equivalent of Python's a if condition else b
? I'm trying to convert something like this
return (quicksort(under) if under else []) + same + (quicksort(over) if over else [])
to Hy. It avoids calling quicksort()
if the list is empty. I know I can do
(if under
(quicksort under)
[])
but I'd rather have it on one line
Hy is a free-form language (like most programming languages, but unlike Python). You can write (if under (quicksort under) [])
in one line, like so, and it makes no difference to the parser.
Whether the Hy compiler produces a Python if
expression or a Python if
statement for your Hy if
form is supposed to be an implementation detail that you don't have to worry about.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.