Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80870
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: isiter builtin |
| Date | 2014-11-16 04:40 -0500 |
| References | <CALW7ahx-7JqxWANNX=JpNFqc0rEghDNMa2kMNiHUYaNzR5WgPw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15879.1416130851.18130.python-list@python.org> (permalink) |
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: isiter builtin Terry Reedy <tjreedy@udel.edu> - 2014-11-16 04:40 -0500
csiph-web