gpt4 book ai didi

c - 大多数 Pythonic 方式等同于 : while ((x = next()) ! = END)

转载 作者:太空狗 更新时间:2023-10-29 18:15:29 25 4
gpt4 key购买 nike

这个 C 结构的最佳 Python 习语是什么?

while ((x = next()) != END) {
....
}

我没有能力重新编码 next()。

更新:答案似乎是:

for x in iter(next, END):
....

最佳答案

@Mark Harrison 的回答:

for x in iter(next_, END):
....

这是来自 Python's documentation 的摘录:

iter(o[, sentinel])

Return an iterator object. ...(snip)... If the second argument, sentinel, is given, then o must be a callable object. The iterator created in this case will call o with no arguments for each call to its next() method; if the value returned is equal to sentinel, StopIteration will be raised, otherwise the value will be returned.

关于c - 大多数 Pythonic 方式等同于 : while ((x = next()) ! = END),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28559/

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