Hy 有内联 if 吗?
Python 的 a if condition else b
的 Hy 等价物是什么? 我正在尝试将这样的东西转换
return (quicksort(under) if under else []) + same + (quicksort(over) if over else [])
为 Hy。如果列表为空,它会避免调用 quicksort()
。我知道我可以
(if under
(quicksort under)
[])
,但我宁愿把它写在一行上
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hy 是一种自由形式的语言(与大多数编程语言类似,但与 Python 不同)。您可以像这样在一行中编写
(if under (quicksort under) [])
,这对解析器没有任何影响。Hy 编译器是否为您的 Hy
if
表单生成 Pythonif
表达式或 Pythonif
语句应该是您不需要的实现细节不必担心。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 Pythonif
statement for your Hyif
form is supposed to be an implementation detail that you don't have to worry about.