gpt4 book ai didi

Python 理解 : for x in [temp for temp in xlist if temp<=xmax]:

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:24 26 4
gpt4 key购买 nike

for x in [temp for temp in xlist if temp<=xmax]: 

此代码有效,但看起来像是一种不必要的外国断断续续的启动 for 循环的方式。

是否有更简洁的语法?

最佳答案

你想在这里做什么?

for x in xlist:
if x > xmax: continue

会起作用。 (你的 for 循环的其余部分是做什么的?)如果它可以只使用一个 list-comp 来完成,那可能是要走的路。如果不能,那么您可能需要上面的成语,或者您将在此处发布的其他答案中看到的一些变体。

关于Python 理解 : for x in [temp for temp in xlist if temp<=xmax]:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11295807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com