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

Lewit, Douglas d-lewit at neiu.edu
Fri Jul 17 21:54:27 CEST 2015


Hey Tim,

I like your solution!  But I'm trying to handle as much of the code myself
without relying on builtin tools.  The builtin tools are awesome, but I
know how my professor thinks.  If there's a harder way to solve a problem,
that's the way he wants me to do it.

I modified my original code and this is what I have.  Although my program
will accept any positive integer between 1 and 10 inclusive, unless you
have a lot of free time on your hands I would not recommend entering an
integer greater than 7 or 8.

Best,

Doug.

P.S.  The itertools package is the best!  I used it a lot last semester
when I took Computational Biology and we had to generate gigantic lists of
various combinations, permutations and products of the nucleotide bases (A,
T, C, G for DNA and A, U, C, G for RNA.)  Curiously enough, if you visit
Amazon.com and search for books on BioInformatics you will end up with a
very long list of books that use Perl rather than Python.  Why is that?



On Fri, Jul 17, 2015 at 1:49 PM, Tim Ottinger <tottinge at gmail.com> wrote:

> 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
>>
>
> _______________________________________________
> 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/95ce4dac/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CartesianN.py
Type: text/x-python-script
Size: 1299 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/chicago/attachments/20150717/95ce4dac/attachment.bin>


More information about the Chicago mailing list