Path: csiph.com!goblin3!goblin.stu.neva.ru!news.netfront.net!not-for-mail From: "Francesco Di Matteo" Newsgroups: it.comp.lang.python Subject: Contatore in funzione ricorsiva Date: Sat, 17 Oct 2015 13:45:43 +0200 Organization: Netfront http://www.netfront.net/ Lines: 33 Message-ID: NNTP-Posting-Host: 87.9.167.150 X-Trace: adenine.netfront.net 1445082354 13207 87.9.167.150 (17 Oct 2015 11:45:54 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Sat, 17 Oct 2015 11:45:54 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 X-Antivirus: avast! (VPS 151016-1, 16/10/2015), Outbound message X-Antivirus-Status: Clean Xref: csiph.com it.comp.lang.python:7596 Ciao a tutti, dovrei usare una routine che genera delle permutazioni di elementi in una lista. In rete ho trovato questa ricorsiva: def perm(n, i): if i == len(n) - 1: print n else: for j in range(i, len(n)): n[i], n[j] = n[j], n[i] perm(n, i + 1) n[i], n[j] = n[j], n[i] # swap back, for the next loop perm([1, 2, 3], 0) che č molto efficiente e compatta, ma non riesco a "numerare" le combinazioni. In pratica non riesco ad inserire un "contatore" nel ciclo ricorsivo che enumeri le combinazioni. Per esempio se voglio un output cosė 1 1,2,3 2 1,3,2 3 2,1,3 ecc.... Chi mi potrebbe dare un suggerimento? Francesco --- news://freenews.netfront.net/ - complaints: news@netfront.net ---