Re: yet another noob question
better (sorry, still learning Python):
def cross(x,y): return [a+b for a in x for y in b]
Jason Nordwick wrote:
better (sorry, still learning Python):
def cross(x,y): return [a+b for a in x for y in b]
Jason Nordwick wrote:
Or without filter:
>
from operator import add
def pr(x): print x
def cross(x,y): return reduce(add, [[a+b for b in y] for a in x])
x=map(pr, reduce(cross, [map(str,range(1 ,6))]*5))
>
>
>
mike_wilson1333 wrote:
>
>
from operator import add
def pr(x): print x
def cross(x,y): return reduce(add, [[a+b for b in y] for a in x])
x=map(pr, reduce(cross, [map(str,range(1 ,6))]*5))
>
>
>
mike_wilson1333 wrote:
>I would like to generate every unique combination of numbers 1-5 in a 5
>digit number and follow each combo with a newline. So i'm looking at
>generating combinations such as: (12345) , (12235), (55554) and so on.
>What would be the best way to do this? So, basically i'm looking for a
>list of all combinations of 1-5 in a 5 digit unique number. Also, when
>I send the list to print there can't be any duplicates of the combos.
>>
>>
> Thanks,
>>
> Mike
>>
>digit number and follow each combo with a newline. So i'm looking at
>generating combinations such as: (12345) , (12235), (55554) and so on.
>What would be the best way to do this? So, basically i'm looking for a
>list of all combinations of 1-5 in a 5 digit unique number. Also, when
>I send the list to print there can't be any duplicates of the combos.
>>
>>
> Thanks,
>>
> Mike
>>
Comment