how can I avoid abusing lists?
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Fri Jul 7 19:38:17 EDT 2006
Peter Otten a écrit :
(snip)
> I don't think your code is ugly. Anyway, here are two more alternatives:
>
>
>>>>types = [0] * 3
>>>>dispatch = [0, 0, 2, 0, 1]
>>>>for value in [1, 1, 0, 4]:
> ... types[dispatch[value]] += 1
> ...
>
>>>>types
>
> [3, 1, 0]
I wonder why I'm still pretending to be a programmer
>
>
>>>>inflated = [0] * 5
>>>>groups = [[0, 1, 3], [4], [2]]
>>>>for value in [1, 1, 0, 4]:
> ... inflated[value] += 1
> ...
>>>>[sum(inflated[i] for i in group) for group in groups]
>
> [3, 1, 0]
>
me-change-job-me-go-selling-pizzas :(
More information about the Python-list
mailing list