Ciao, Il giorno 24 aprile 2017 17:51, Marcello <marce...@linuxvil.it> ha scritto:
> Ciao a tutti, > > devo ordinare un dizionario in base al nome. > Ho provato, cercando sul web, OrderedDict dovrebbe essere quello che fa al > caso mio. > > import collections > diz = [{'add': '10', 'name': 'ccc', 'pwd': '12'}, {'add': '11', 'name': > 'aaa', 'pwd': '45'}, {'add': '12', 'name': 'bbb', 'pwd': '79'}] > print (collections.OrderedDict(sorted(diz.items(), key=lambda t: t[1]))) > > ma mi viene restituito un errore > AttributeError: 'list' object has no attribute 'items' > > E' come se diz venisse visto come lista e non come dizionario. > diz in effetti è una lista con dentro n-dizionari :) -- "Unix IS user friendly. It's just selective about who its friend 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"
_______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python