[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:16:36 2003


Hi Fred,

>  >>> list2 = [list1[i]*(i%n!=n-1) ....

Oh very good! I hadn't thought about using a boolean test 
to null out the values.

> or 'new item' 

And then using those null values to force an 'or' through 
is inspired. I had thought of using and/or logic in a comprehension, 
but never thought of the ( * <expression> ) trick.

Nice one.

Alan G