Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87683

Re: Brilliant or insane code?

References <mailman.507.1426638964.21433.python-list@python.org> <meajh1$hr0$2@dont-email.me>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-03-18 08:59 -0600
Subject Re: Brilliant or insane code?
Newsgroups comp.lang.python
Message-ID <mailman.3.1426690849.10327.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Mar 17, 2015 at 7:14 PM, Dan Sommers <dan@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Brilliant or insane code? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-18 00:35 +0000
  Re: Brilliant or insane code? Dan Sommers <dan@tombstonezero.net> - 2015-03-18 01:14 +0000
    Re: Brilliant or insane code? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-18 13:25 +1100
      Re: Brilliant or insane code? Dan Sommers <dan@tombstonezero.net> - 2015-03-18 03:06 +0000
    Re: Brilliant or insane code? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-18 08:59 -0600
    Re: Brilliant or insane code? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-18 15:20 +0000

csiph-web