Brilliant or insane code?

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Mar 18 11:20:12 EDT 2015


On 18/03/2015 14:59, Ian Kelly wrote:
> On Tue, Mar 17, 2015 at 7:14 PM, Dan Sommers <dan at tombstonezero.net> wrote:
>> On Wed, 18 Mar 2015 00:35:42 +0000, Mark Lawrence wrote:
>>
>>> I've just come across this
>>> http://www.stavros.io/posts/brilliant-or-insane-code/ as a result of
>>> this http://bugs.python.org/issue23695
>>>
>>> Any and all opinions welcomed, I'm chickening out and sitting firmly
>>> on the fence.
>>
>> According to the article itself, "it relies in an implementation detail
>> (the order the zip function iterates over the arrays) to work."  Then
>> again, the article also points to the official docs that says that this
>> implementation detail is guaranteed.
>>
>> So it's no worse than depending on some weird but *documented* corner of
>> the IEEE-754 or POSIX spec.
>
> In fact, this is also a code recipe found in the itertools
> documentation. The official docs don't just guarantee it; they
> *recommend* it.
>
> def grouper(iterable, n, fillvalue=None):
>      "Collect data into fixed-length chunks or blocks"
>      # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
>      args = [iter(iterable)] * n
>      return zip_longest(*args, fillvalue=fillvalue)
>
> https://docs.python.org/3.4/library/itertools.html
>

Which is available here https://pypi.python.org/pypi/more-itertools 
along with many other goodies.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list