[Tutor] Sequences of letter

Rich Lovely roadierich at googlemail.com
Tue Apr 13 02:14:18 CEST 2010

On 13 April 2010 01:07, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "Steven D'Aprano" <steve at pearwood.info> wrote
>>>>> import itertools
>>>>> for x in itertools.product('abc', 'abc', 'abc'):
>> If you don't like the repeated 'abc' in the call to product(), it can be
>> written as itertools.product(*['ab']*3) instead.
> Nope, I think the repeated string is much clearer, and thus better,
> than the cryptogram thanks very much! :-)
> But I like the itertools solution.
> I really, really, need to spend some time playing with itertools.
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

itertools.product() also has the repeat keyword argument:

for x in itertools.product('abc', 'abc', 'abc'):

is the same as

for x in itertools.product('abc', repeat=3):

Rich "Roadie Rich" Lovely

Just because you CAN do something, doesn't necessarily mean you SHOULD.
In fact, more often than not, you probably SHOULDN'T.  Especially if I
suggested it.

10 re-discover BASIC
20 ???
30 PRINT "Profit"
40 GOTO 10

More information about the Tutor mailing list