Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87684
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: Brilliant or insane code? |
| Date | 2015-03-18 15:20 +0000 |
| References | <mailman.507.1426638964.21433.python-list@python.org> <meajh1$hr0$2@dont-email.me> <CALwzid=Y0uQLaPHa8g2fJko9uDJrMLp9-GK7966yXaRkx3TKWQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4.1426692040.10327.python-list@python.org> (permalink) |
On 18/03/2015 14:59, Ian Kelly wrote:
> 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
>
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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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