Re: assignment in a for loop

2006-05-17 Thread bruno at modulix
MackS wrote: (snip) >>What's preventing the use of list comprehensions? >> >>new_list = [x+1 for x in old_list] > > Suppose I want to do anything as trivial as modify the values of the > list members _and_ print their new values. Then it's a sure design smell IMHO. Don't mix presentation wi

Re: assignment in a for loop

2006-05-16 Thread Ben Finney
"MackS" <[EMAIL PROTECTED]> writes: > Thank you for your reply. A pleasure to help. > > What's preventing the use of list comprehensions? > > > > new_list = [x+1 for x in old_list] > > Suppose I want to do anything as trivial as modify the values of the > list members _and_ print their new

Re: assignment in a for loop

2006-05-16 Thread MackS
Thank you for your reply. > > 1) Is what I wrote above (minimally) correct? > > Correct for what? You can tell if it's *syntactically* correct by > simply running it. > > As for any other "correct", define that. Does it do what you want it > to do? I was referring to my attempted explanation, no

Re: assignment in a for loop

2006-05-16 Thread Ben Finney
"MackS" <[EMAIL PROTECTED]> writes: [MackS, please don't top-post.] > Suppose I want to do modify all arguments which are passed to a > function. Do I need to use a list comprehension such as > > def f(arg1,arg2,arg3): > > arg1,arg2,arg3 = [i+1 for i in (arg1,arg2,arg3)] > ... > > Th

Re: assignment in a for loop

2006-05-16 Thread Ben Finney
"MackS" <[EMAIL PROTECTED]> writes: > >>> l = [1,2] > >>> for i in l: > ... i = i + 1 > ... > >>> l > [1, 2] > > I understand (I think!) that this is due to the fact that in Python > what looks like "assignment" really is binding a name to an > object. The result is that inside the loop I am

Re: assignment in a for loop

2006-05-16 Thread MackS
Sorry, my previous post probably was not very good at explaining _why_ I want to do this. Suppose I want to do modify all arguments which are passed to a function. Do I need to use a list comprehension such as def f(arg1,arg2,arg3): arg1,arg2,arg3 = [i+1 for i in (arg1,arg2,arg3)] ...

assignment in a for loop

2006-05-16 Thread MackS
Hello everyone Consider the following >>> l = [1,2] >>> for i in l: ... i = i + 1 ... >>> l [1, 2] I understand (I think!) that this is due to the fact that in Python what looks like "assignment" really is binding a name to an object. The result is that inside the loop I am creating an objec