Questions tagged «yield-from»

6
将“ yield from”语句转换为Python 2.7代码
我在Python 3.2中有一个下面的代码,我想在Python 2.7中运行它。我确实进行了转换(missing_elements在两个版本中都放了代码),但是我不确定这是否是最有效的方法。基本上,如果函数的yield from上半部和下半部有两个类似下面的调用,会发生什么情况missing_element?是否将两个半部分(上半部分和下半部分)中的条目彼此追加到一个列表中,以便父递归函数与yield from调用一起使用,并将两个半部分一起使用? def missing_elements(L, start, end): # Python 3.2 if end - start <= 1: if L[end] - L[start] > 1: yield from range(L[start] + 1, L[end]) return index = start + (end - start) // 2 # is the lower half consecutive? consecutive_low = L[index] == …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.