Re: change vars in place w/loop or list comprehension

2005-05-31 Thread Peter Hansen
[EMAIL PROTECTED] wrote: > I am a python newbie, and am grappling with a fundamental concept. I > want to > modify a bunch of variables in place. Consider the following: > [snip] a = 'one' b = 'two' c = 'three' [a, b, c] = [s.upper() for s in [a, b, c]] > > Both of these accompl

Re: change vars in place w/loop or list comprehension

2005-05-31 Thread Raymond Hettinger
> >>> a = 'one' > >>> b = 'two' > >>> c = 'three' > >>> [a, b, c] = [s.upper() for s in [a, b, c]] > >>> a > 'ONE' > > Both of these accomplish what I'm after; I prefer the second for its > brevity. But either approach requires that I spell out my list of > vars-to-alter [a, b, c] twice. This stri

Re: change vars in place w/loop or list comprehension

2005-05-31 Thread Jatinder Singh
Hi what u can do over here is add a,b,c... in a list e.g. list.append(vars..) and then use the statement newlist = map(lambda x:x.upper(),list) Now ur newlist will contain the modified list. HOPE THIS THE BETTER SOLUTION TO UR PROBLEM Quoting [EMAIL PROTECTED]: > I am a python newbie, and am g

change vars in place w/loop or list comprehension

2005-05-31 Thread ken . boss
I am a python newbie, and am grappling with a fundamental concept. I want to modify a bunch of variables in place. Consider the following: >>> a = 'one' >>> b = 'two' >>> c = 'three' >>> list = [a, b, c] >>> for i in range(len(list)): ... list[i] = list[i].upper() ... >>> [a, b, c] = list >>>