Path: csiph.com!aioe.org!bofh.it!tornado.fastwebnet.it!53ab2750!not-for-mail From: Mauro Casini Newsgroups: it.comp.lang.python Subject: Re: List sorted References: Message-ID: <87y45ex0wm.fsf@debian.lan> Organization: . User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:8b/K4GcxdHPrJoli0pMXAcCh7mA= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lines: 19 Date: Wed, 06 Jul 2016 17:05:13 +0200 NNTP-Posting-Host: 93.44.191.120 X-Complaints-To: newsmaster@fastweb.it X-Trace: tornado.fastwebnet.it 1467817513 93.44.191.120 (Wed, 06 Jul 2016 17:05:13 CEST) NNTP-Posting-Date: Wed, 06 Jul 2016 17:05:13 CEST Xref: csiph.com it.comp.lang.python:7672 Smith writes: > ho una lista di stringhe e vorrei ordinarle e numerarle, ma > questo script non restituisce il risultato desiderato. [...] > for i, v in sorted(enumerate(['tic', 'tac', 'toe','capo'])): > print(i,v) Così prima numeri la lista poi la ordini in base al numero appena messo (mantenendo ovviamente lo stesso ordine). Per ottenere quello che ti serve, devi prima ordinare la lista e dopo mettere i numeri alla lista già ordinata: for i, v in enumerate(sorted(['tic', 'tac', 'toe','capo'])): print(i, v) ciao, Mauro