This issue has been migrated to GitHub: https://github.com/python/cpython/issues/49284
classification
process
Created on 2009-01-22 18:18 by lehmannro, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Files |
|
|
|
File name |
Uploaded |
Description |
Edit |
fixlen.patch |
lehmannro,2009-01-22 18:18 |
patch to trunk |
|
Messages (5) |
|
|
msg80372 - (view) |
Author: Robert Lehmann (lehmannro) * |
Date: 2009-01-22 18:18 |
As raised recently on python-ideas [1]_, an itertools method fixing iterators to a certain length might be handy (where fixing is either cutting elements off or appending values). I appended a patch implementing this feature in Python/C, unit tests and documentation included. .. [1] http://thread.gmane.org/gmane.comp.python.ideas/2472/focus=2479 |
|
|
msg80378 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2009-01-22 21:21 |
"Return an iterator fixing *iterable*\ 's length to *length* by either cutting elements off or adding *value* to the iterable." Rather than mixing both, it would be more flexible to have a separate function for each IMO. Cutting off is already be handled by islice() (isn't it?), and padding should be done with a function called e.g. pad() or rpad(). |
|
|
msg80383 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2009-01-22 21:50 |
Am taking this under advisement but am initially disinclined. It is not a basic itertool since it can be composed from the others. Also, it's use cases seem to be few. One challenge for the module is that adding more tools makes the overall toolkit harder to use because the number of choices is increased. |
|
|
msg80418 - (view) |
Author: Robert Lehmann (lehmannro) * |
Date: 2009-01-23 15:34 |
When I started writing this patch this was actually what I intended. But having ``fixlen(range(3), 2)`` return 0 1 2 struck me as odd. Renaming the function to `pad` would help there indeed. It depends on which use case is more common: either fixing an iterator to a certain length (slicing/padding applied as required) or obtaining an iterator of *at least* some number of elements (padded as required)? The thread on python-ideas suggests the latter while the example Python code brought up there implements the former. OTOH the latter cannot be composed *that easily* of other itertools but the former is more useful for unpacking. On a related note: what should happen if `length` is negative? `itertools.repeat` just defaults to 0 in such cases but I am unsure how applicable that is in this case. |
|
|
msg80483 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2009-01-24 21:42 |
Am still leaning towards rejecting this one based on: * paucity of use cases * non-atomicity (it can be built-out of existing tools) * minimizing the number of tools in the toolkit * not convinced that padded tuple unpacking is desirable |
|
|
History |
|
|
|
Date |
User |
Action |
Args |
2022-04-11 14:56:44 |
admin |
set |
github: 49284 |
2009-01-27 05:15:45 |
rhettinger |
set |
status: open -> closedresolution: rejected |
2009-01-24 21:42:04 |
rhettinger |
set |
messages: + |
2009-01-23 15:34:06 |
lehmannro |
set |
messages: + |
2009-01-22 21:50:52 |
rhettinger |
set |
messages: + |
2009-01-22 21:21:40 |
pitrou |
set |
nosy: + pitroumessages: + |
2009-01-22 18:44:38 |
rhettinger |
set |
assignee: rhettingernosy: + rhettingerversions: + Python 3.1 |
2009-01-22 18🔞41 |
lehmannro |
create |
|