list comprehension in python

[b]list:[/b]
points=[('118.696', '55.016'), ('64.583', '195.986'), ('229.826', '259.417'), ('283.94', '118.447')]


[b]list comprehension:[/b]
[Decimal(x),Decimal(y) for x,y in points]

SyntaxError: invalid syntax

[(Decimal(x),Decimal(y)) for x,y in points]


[b]Conclusion:[/b]
if you want to return a tuple, you have to speak it out:-)

[b]another list comprehension:[/b]
for i,x,y in points:

[b]result[/b]:SyntaxError: invalid syntax

[b]try again:[/b]
for i,(x,y) in points:


[b]conclusion[/b]:if you want to get a tuple, you'd better not put it next to others, here is index i, instead make it clear that it's a tuple.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值