[issue18821] Add .lastitem attribute to takewhile instances

2013-09-08 Thread Oscar Benjamin
Oscar Benjamin added the comment: Thank you Claudiu very much for writing a patch; I was expecting to have to do that myself! Serhiy, you're right groupby is a better fit for this. It does mean a bit of reworking for the (more complicated) sum function I'm working on but I've just checked with t

[issue18821] Add .lastitem attribute to takewhile instances

2013-09-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: Oscar, the solution proposed by Serhiy looks like a better choice. I'm wary of increasing the API complexity of the itertools. Right now, their learnability is aided by having simple signatures and no side-values. The itertools are modeled on functional to

[issue18821] Add .lastitem attribute to takewhile instances

2013-09-07 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Oscar, did you considered itertools.groupby()? Perhaps it better meets your needs. -- nosy: +serhiy.storchaka ___ Python tracker ___

[issue18821] Add .lastitem attribute to takewhile instances

2013-09-07 Thread Claudiu.Popa
Claudiu.Popa added the comment: Hello. Here's a basic patch with tests which accomplishes your request. Currently, it defaults to None if no item failed, but probably it can be set only when something fails the predicate (and the user will check using hasattr(t, 'last') ). -- keywords

[issue18821] Add .lastitem attribute to takewhile instances

2013-08-31 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http

[issue18821] Add .lastitem attribute to takewhile instances

2013-08-23 Thread Ned Deily
Changes by Ned Deily : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

[issue18821] Add .lastitem attribute to takewhile instances

2013-08-23 Thread Oscar Benjamin
New submission from Oscar Benjamin: I've often wanted to be able to query a takewhile object to discover the item that failed the predicate but the item is currently discarded. A usage example: def sum(items): it = iter(items) ints = takewhile(Integral.__instancecheck__, it) subtot