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


Groups > comp.lang.python > #80870

Re: isiter builtin

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '*not*': 0.07; 'string': 0.09; 'excluding': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; "('b',": 0.16; "[('a',": 0.16; 'arg,': 0.16; 'garrett': 0.16; 'iterable:': 0.16; 'iterated': 0.16; 'iterator,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'renamed': 0.16; 'wrote:': 0.18; 'replacing': 0.19; 'written': 0.21; 'input': 0.22; 'header:User-Agent:1': 0.23; 'enhanced': 0.24; 'second': 0.26; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'besides': 0.30; 'code': 0.31; 'checking': 0.33; 'could': 0.34; 'but': 0.35; 'there': 0.35; 'yield': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'such': 0.63; 'more': 0.64; 'received:fios.verizon.net': 0.84; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: isiter builtin
Date Sun, 16 Nov 2014 04:40:22 -0500
References <CALW7ahx-7JqxWANNX=JpNFqc0rEghDNMa2kMNiHUYaNzR5WgPw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-108-16-203-145.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <CALW7ahx-7JqxWANNX=JpNFqc0rEghDNMa2kMNiHUYaNzR5WgPw@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15879.1416130851.18130.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416130851 news.xs4all.nl 2832 [2001:888:2000:d::a6]:49856
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80870

Show key headers only | View raw


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


Thread

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

csiph-web