Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80870 > unrolled thread

Re: isiter builtin

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-11-16 04:40 -0500
Last post2014-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.


Contents

  Re: isiter builtin Terry Reedy <tjreedy@udel.edu> - 2014-11-16 04:40 -0500

#80870 — Re: isiter builtin

FromTerry Reedy <tjreedy@udel.edu>
Date2014-11-16 04:40 -0500
SubjectRe: 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web