Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44596 > unrolled thread
| Started by | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| First post | 2013-05-01 19:19 +0300 |
| Last post | 2013-05-01 09:30 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Why chunks is not part of the python standard lib? Serhiy Storchaka <storchaka@gmail.com> - 2013-05-01 19:19 +0300
Re: Why chunks is not part of the python standard lib? Paul Rubin <no.email@nospam.invalid> - 2013-05-01 09:30 -0700
| From | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| Date | 2013-05-01 19:19 +0300 |
| Subject | Re: Why chunks is not part of the python standard lib? |
| Message-ID | <mailman.1219.1367425160.3114.python-list@python.org> |
01.05.13 09:26, Ricardo Azpeitia Pimentel написав(ла):
> After reading How do you split a list into evenly sized chunks in
> Python?
> <http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python>
> and seeing this kind of mistakes happening
> https://code.djangoproject.com/ticket/18972 all the time.
>
> Why is not a |chunks| function in itertools?
Because not every 1 line function needs to be in the standard library.
> |chunks([1, 2, 3, 4, 5], 3)
> # Should return [[1, 2, 3], [4, 5]] or the iterator equivalent.|
def chunks(seq, size):
return [seq[i: i + size] for i in range(0, len(seq), size)]
[toc] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2013-05-01 09:30 -0700 |
| Message-ID | <7xy5byacis.fsf@ruckus.brouhaha.com> |
| In reply to | #44596 |
Serhiy Storchaka <storchaka@gmail.com> writes: > def chunks(seq, size): > return [seq[i: i + size] for i in range(0, len(seq), size)] That's just for lists. An itertools version would work with arbitrary iterables. I've also had to rewrite that function more times than seems proper.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web