[Python] iterazione incontrollata

Francesco Pischedda francesco.pischedda a gmail.com
Dom 26 Apr 2020 13:28:47 CEST


Buondí

Il giorno dom 26 apr 2020 alle ore 13:02 Carpediem <i.carpediem a tiscali.it>
ha scritto:

> Buongiorno lista, approfittando di questo periodo, ho ripreso a cimentarmi
> col caro python e mi sono imbattutto in una situazione che non riesco a
> risolvere:
>
> ho due liste; nella prima (capitali) sono riportati i nomi delle
> principali città del mondo (una trentina) e nella seconda lista,
> (temperature) in corrispondenza di posizione di ogni capitale, la
> temperatura massima della giornata.
>
> volevo fare in modo che queste due liste venissero ordinate in modo tale
> che temperature e nomi delle capitali vengano riportate in ordine
> decrescente sulla base delle temperature.
>
> [...]

> Suggerimenti? Soluzioni?
>
> una possibile soluzione potrebbe essere la seguente

>>> cities = ["Rome", "Berlin", "Paris"]
>>> temperatures = [25, 17, 21]
>>> sorted(zip(cities, temperatures), key=lambda t: t[1])
[('Berlin', 17), ('Paris', 21), ('Rome', 25)]

Se hai dubbi chiedi pure.

Ciao,
Francesco
-- 
"I really detest the use of the word "training" in relation to professional
activities. Training is what you do to dogs. What you should be doing with
people is educating them, not training them. There is a big, big
difference." - Ron Garret

"Unix IS user friendly. It's just selective about who its friends are"

"Nevertheless I still think it’s a bad idea to make things harder for
ourselves if we can avoid it."

"C is quirky, flawed, and an enormous success."
                                   -- Dennis Ritchie

"Shipping is a feature. A really important feature. Your product must have
it."

"There is no such a thing as a temporary change or workaround: In most
cases, workarounds are tech debt."

"La gatta frettolosa ha fatto i gattini ciechi"
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20200426/10311edf/attachment.html>


Maggiori informazioni sulla lista Python