Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.python > #7596

Contatore in funzione ricorsiva

Path csiph.com!goblin3!goblin.stu.neva.ru!news.netfront.net!not-for-mail
From "Francesco Di Matteo" <frankdimat@TEMPOlibero.it>
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 <mvtcdh$csn$1@adenine.netfront.net> (permalink)
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

Show key headers only | View raw


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 ---

Back to it.comp.lang.python | Previous | NextNext in thread | Find similar


Thread

Contatore in funzione ricorsiva "Francesco Di Matteo" <frankdimat@TEMPOlibero.it> - 2015-10-17 13:45 +0200
  Re: Contatore in funzione ricorsiva Leonardo Serni <lserni@gmail.com> - 2015-10-17 15:10 +0200
  Re: Contatore in funzione ricorsiva Antonio Valentino <antonio.valentino@tiscali.it> - 2015-10-17 17:22 +0200
    Re: Contatore in funzione ricorsiva "Francesco Di Matteo" <frankdimat@TEMPOlibero.it> - 2015-10-17 18:22 +0200

csiph-web