[Python] Il dilemma degli array mutabili

Nicola Larosa nico a tekNico.net
Gio 19 Set 2013 17:11:50 CEST


> Piergiuliano Bossi ha scritto:
>> def useless(list):
>>     return [list[i] for i in range(len(list)) if evaluate(list[:i] +
>> list[i+1:]) == evaluate(list)]

Marco Beri wrote:
> Questo codice può diventare un più chiaro con enumerate:
> 
> def useless(list):
>     return [val for i, val in enumerate(list) if evaluate(list[:i] +
> list[i+1:]) == evaluate(list)]

Meglio non usare "list" come nome, perchè copre il builtin.

-- 
Nicola Larosa - http://www.tekNico.net/

I'll play closed-source games because they're not very harmful, and
it doesn't bother me when I ride an elevator with closed-source
firmware, but I will not - ever, under any circumstances, for any
reason - give Apple my money or my approval so that it can lock more
people into its beautifully-decorated jails. - Eric Raymond, April 2013



Maggiori informazioni sulla lista Python