[python] Vypocet variaci

Ing. Jan Janech devel na atlas.sk
Čtvrtek Listopad 15 18:57:32 CET 2007


Jan Jakubuv wrote:
> 2007/11/15, Ing. Jan Janech <devel na atlas.sk>:
>> Pre milovnikov in-linerov:
>>
>>  >>> variations  = lambda lst: [[lst[x]]+y for x in xrange(len(lst)) for
>> y in variations(lst[:x]+lst[x+1:])]+(((len(lst) == 1) and [lst]) or [])
>>
> 
> nadhera! ale jen tak mimochodem, to sou permutace ;-)

sakra... fakt :D nuz algebra je uz davno za mnou :D

To je jedno

tak zadefinujem obe:

 >>> perm = lambda lst: [[lst[x]]+y for x in xrange(len(lst)) for y in 
perm(lst[:x]+lst[x+1:])]+(((len(lst) == 1) and [lst]) or [])

 >>> vari = lambda lst, n: list(set(p[:n] for p in perm(lst)))


:D :D

> 
> honza.
> _______________________________________________
> Python mailing list
> Python na py.cz
> http://www.py.cz/mailman/listinfo/python
> 
> 
> 
> 
> 




Další informace o konferenci Python