Thanks, ChrisA On Tue, Nov 22, 2016 at 9:24 PM, Chris Angelico <ros...@gmail.com> wrote:
> On Wed, Nov 23, 2016 at 2:14 PM, Nathan Ernst <nathan.er...@gmail.com> > wrote: > > I was not aware of that PEP. > > > > The logic in my function is exactly as desired, so to squelch the > warning, > > I merely wrapped the iteration in a try/except: > > > > def adjacent_difference(seq, selector=identity): > > i = iter(seq) > > l = selector(next(i)) > > try: > > while True: > > r = selector(next(i)) > > yield r - l > > l = r > > except StopIteration: > > return > > You'll probably want to move the 'try' up one line - unless you want > an exception if the sequence is empty. And it's exactly this kind of > ambiguity that this change helps to catch. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list