Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80870 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2014-11-16 04:40 -0500 |
| Last post | 2014-11-16 04:40 -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: isiter builtin Terry Reedy <tjreedy@udel.edu> - 2014-11-16 04:40 -0500
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-11-16 04:40 -0500 |
| Subject | Re: isiter builtin |
| Message-ID | <mailman.15879.1416130851.18130.python-list@python.org> |
On 11/16/2014 2:57 AM, Garrett Berg wrote:
> (how often have you iterated over a string?)
Often enough, but perhaps more often have written functions for which a
string is as valid an input as many other iterables.
def cross(iterable, reiterable):
for a in iterable:
for b in reiterable:
yield a, b
print(list(cross('ab', 'cde')))
# [('a', 'c'), ('a', 'd'), ('a', 'e'), ('b', 'c'), ('b', 'd'), ('b', 'e')]
For me, there is no point in excluding such input and output.
(And yes, the code above could be enhanced by at least checking that
reiterable is *not* an iterator, or by replacing the second arg, renamed
iterable2, with list(iterable2), but this is besides the point.)
--
Terry Jan Reedy
Back to top | Article view | comp.lang.python
csiph-web