Question about permutations (itertools)

Vincent Davis vincent at vincentdavis.net
Mon May 31 10:31:38 EDT 2010


On Mon, May 31, 2010 at 8:17 AM, Xavier Ho <contact at xavierho.com> wrote:
>
>> >>> list(combinations_with_replacement('01',3))
>> ('0', '0', '0')
>> ('0', '0', '1')
>> ('0', '1', '1')
>> ('1', '1', '1')
>>
>> Is it possible to get combinations_with_replacement to return numbers
>> rather than strings? (see above)
>
>>>> list(combinations_with_replacement(range(0,2), 3))
> [(0, 0, 0), (0, 0, 1), (0, 1, 1), (1, 1, 1)]

Thanks, for some reason I didn't combinations_with_replacement took a
list as an argument.

> Hopefully that'll give you some ideas.
>
> Cheers,
> Xav



More information about the Python-list mailing list