[Tutor] Can you modify every nth item in a list with a single assignment?

Jeff Shannon jeff@ccvcorp.com
Thu Jun 12 20:14:02 2003


Bob Gailer wrote:

> What we need here is a new language feature that lets us provide a 
> sequence of index values to a list. Something like:
>
> MyList[(1,4,9,23)] = MyList[(1,4,9,23)] + 43


This can be done easily enough without adding a new feature, it just 
takes two lines instead of one:

for n in (1,4,9,23):
   MyList[n] += 43

Jeff Shannon
Technician/Programmer
Credit International