【发布时间】:2012-08-26 12:21:19
【问题描述】:
是否有与 Haskell 'let' 表达式等效的 Python 表达式,可以让我编写如下内容:
list2 = [let (name,size)=lookup(productId) in (barcode(productId),metric(size))
for productId in list]
如果不是,那么最易读的替代方案是什么?
添加以澄清 let 语法:
x = let (name,size)=lookup(productId) in (barcode(productId),metric(size))
等价于
(name,size) = lookup(productId)
x = (barcode(productId),metric(size))
不过,第二个版本不能很好地处理列表推导。
【问题讨论】:
-
请举例说明您想要的输入和输出,以阐明 Haskell
let构造在做什么。
标签: python haskell functional-programming let