Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我怎样才能将以下内容转换为hy?
hy
dct = { 1:2, 3:4 } print([i*j for i, j in dct.items()]) # => [2, 12]
我对您的标题感到困惑,因为您的示例中只有一个迭代子句,但无论如何,这是一个 Hy 字面翻译:
(setv dct {1 2 3 4}) (print (lfor [i j] (.items dct) (* i j))) ; => [2, 12]
但是您也可以使用阴影乘法运算符来执行此操作:
(import hy.pyops *) (setv dct {1 2 3 4}) (print #* (map * (.keys dct) (.values dct))) ; => 2 12