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


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

Re: List sorted

Subject Re: List sorted
References <qP8fz.47066$pt.44734@tornado.fastwebnet.it> <87y45ex0wm.fsf@debian.lan>
Newsgroups it.comp.lang.python
From Smith <smith@smith.it>
Message-ID <577D3C1A.1090006@smith.it> (permalink)
Date 2016-07-06 19:12 +0200

Show all headers | View raw


On 06/07/2016 17:05, Mauro Casini wrote:
> Smith <smith@smith.com> 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

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


Thread

List sorted Smith <smith@smith.com> - 2016-07-06 16:44 +0200
  Re: List sorted Mauro Casini <mauro@iperbole.bologna.it> - 2016-07-06 17:05 +0200
    Re: List sorted Smith <smith@smith.it> - 2016-07-06 19:12 +0200

csiph-web