[Tutor] Can you modify every nth item in a list with a single assignment?
Alan Gauld
alan.gauld@blueyonder.co.uk
Fri Jun 13 03:06:01 2003
> >> MyList[(1,4,9,23)] = MyList[(1,4,9,23)] + 43
>
> Or another healthy alternative, on one line:
>
> map((lambda x: x + 43), [1, 4, 9, 23])
Nope, this adds 43 to each of the 4 numbers, but
the original suggestion was that we should add 43
to each element of the llist indexed by those numbers.
ie
MyList[1] + 43
MyList[4] + 43
etc...
But Jeff's solution still looks like a good one to me.
If a feature only saves one line of code then leave it
out is my motto!
Alan G.