Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82854 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2014-12-23 15:46 -0500 |
| Last post | 2014-12-23 15:46 -0500 |
| Articles | 1 — 1 participant |
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: learning to use iterators Terry Reedy <tjreedy@udel.edu> - 2014-12-23 15:46 -0500
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-12-23 15:46 -0500 |
| Subject | Re: learning to use iterators |
| Message-ID | <mailman.17165.1419367616.18130.python-list@python.org> |
On 12/23/2014 1:55 PM, Seb wrote: >>>> def n_grams(a, n): > ... z = (islice(a, i, None) for i in range(n)) > ... return zip(*z) > I'm impressed at how succinctly this islice helps to build a list of > tuples with indices for all the required windows. However, I'm not > quite following what goes on in the first line of the function. > Particulary, what do the parentheses do there? The parenthesized expression is a generator expression. The ()s are part of the syntax and may only be omitted when the expression is the argument of a function call, as in >>> list((i for i in range(0, 7, 2))) [0, 2, 4, 6] >>> list(i for i in range(0, 7, 2)) [0, 2, 4, 6] -- Terry Jan Reedy
Back to top | Article view | comp.lang.python
csiph-web