Re: eliminare elementi doppi in un array
Von: Lawrence Oluyede (raims@dot.com) [Profil]
Datum: 01.07.2008 23:04
Message-ID: <1ijf8u0.57ziizb1kmgwN%raims@dot.com>
Newsgroup: it.comp.lang.python
Datum: 01.07.2008 23:04
Message-ID: <1ijf8u0.57ziizb1kmgwN%raims@dot.com>
Newsgroup: it.comp.lang.python
Antonio Cuni <antoPUNTOcuni@gmail.com> wrote: > Se siamo sicuri che gli elementi siano hashabili, questa è una possibile > soluzione (non testata): > > def add(myset, item): > myset.add(item) > return item > > seen = set() > mylist = [add(seen, item) for item in mylist if item not in seen] Che ne dici della soluzione che si trova in coda al recipe di bearophile? """ def unique(seq): return dict.fromkeys(seq).keys() """ -- Lawrence, oluyede.org - neropercaso.it - stacktrace.it "It is difficult to get a man to understand something when his salary depends on not understanding it" - Upton Sinclair[ Auf dieses Posting antworten ]
