[Chicago] Cartesian 1111 to 4444.....to nnnn (general case)

Tim Ottinger tottinge at gmail.com
Fri Jul 17 20:49:57 CEST 2015


did you use this:

number_of_lists = 4
numbers = range(10)
print list( itertools.product(*[numbers]*number_of_lists))


Yields a list from 1,1,1,1 to 9,9,9,9 given that all lists are identical in
content.
number of lists and length of list are variable.
Inner ranges could be iterators too, to avoid having memory chewed up by
Note, the above example lets memory be consumed by list() and range().



On Fri, Jul 17, 2015 at 7:38 AM Carl Karsten <carl at personnelware.com> wrote:

>     def __init__(self, int1 = 1, int2 = 1, int3 = 1, int4 = 0):
>         self.int1 = int1
>         self.int2 = int2
>         self.int3 = int3
>         self.int4 = int4
>
> 1,2,3,4 hard coded is generally a red flag that you should be using a list.
>
> I didn't look at what the code is doing, but you should be able to replace
> all the int1 with i[1]
> (don't use int[1], int is a reserved word)
>
> Step 2: Once you have that working, you should be able to replace all the
> 1,2,3,4's with for n in range(1,5): i[n]
>
>
>
> On Fri, Jul 17, 2015 at 12:30 AM, Lewit, Douglas <d-lewit at neiu.edu> wrote:
>
>> I think this works!  Yay!!!  Although I would like to make it more
>> general for any integer n besides 4.  Do I really need int1, int2, int3,
>> int4?  I think all I need is the initial vector = [1, 1, 1, 1, ......, 0].
>>
>> Gotta go!  Oh yeah, code here is in Python 3.  Not sure how well it will
>> run in Python 2.  I don't know when Python 4 is coming out, but if it's not
>> backward compatible with Python 3 I have a feeling A LOT of folks in the
>> Python community are going to be very, very upset!
>>
>> Best,
>>
>> Doug.
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> https://mail.python.org/mailman/listinfo/chicago
>>
>>
>
>
> --
> Carl K
>
>  _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150717/7a8f306e/attachment.html>


More information about the Chicago mailing list