Path: csiph.com!news.fcku.it!bofh.it!tornado.fastwebnet.it!53ab2750!not-for-mail Subject: Re: List sorted References: <87y45ex0wm.fsf@debian.lan> Newsgroups: it.comp.lang.python From: Smith Message-ID: <577D3C1A.1090006@smith.it> User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <87y45ex0wm.fsf@debian.lan> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Lines: 22 Date: Wed, 6 Jul 2016 19:12:58 +0200 NNTP-Posting-Host: 93.34.176.20 X-Complaints-To: newsmaster@fastweb.it X-Trace: tornado.fastwebnet.it 1467825178 93.34.176.20 (Wed, 06 Jul 2016 19:12:58 CEST) NNTP-Posting-Date: Wed, 06 Jul 2016 19:12:58 CEST Xref: csiph.com it.comp.lang.python:7673 On 06/07/2016 17:05, Mauro Casini wrote: > 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 > Grazie Mauro