looking for a neat solution to a nested loop problem

Oscar Benjamin oscar.benjamin at bristol.ac.uk
Mon Aug 6 12:00:29 EDT 2012


Are you familiar with the itertools module?
itertools.product is designed for this purpose:
http://docs.python.org/library/itertools#itertools.product
Oscar.
On 6 August 2012 16:52, Tom P <werotizy at freent.dd> wrote:
> consider a nested loop algorithm -
>> for i in range(100):
> for j in range(100):
> do_something(i,j)
>> Now, suppose I don't want to use i = 0 and j = 0 as initial values, but
> some other values i = N and j = M, and I want to iterate through all 10,000
> values in sequence - is there a neat python-like way to this? I realize I
> can do things like use a variable for k in range(10000): and then derive
> values for i and j from k, but I'm wondering if there's something less
> clunky.
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120806/4725011e/attachment.html>


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /