How could I convert the following to hy?
dct = { 1:2, 3:4 }
print([i*j for i, j in dct.items()])
# => [2, 12]
How could I convert the following to hy?
dct = { 1:2, 3:4 }
print([i*j for i, j in dct.items()])
# => [2, 12]
I'm puzzled by your title, since there's only one iteration clause in your example, but anyway, here's a literal Hy translation:
(setv dct {1 2 3 4})
(print (lfor [i j] (.items dct) (* i j)))
; => [2, 12]
But you could also do this with the shadow multiplication operator:
(import hy.pyops *)
(setv dct {1 2 3 4})
(print #* (map * (.keys dct) (.values dct)))
; => 2 12