[Tutor] better map/lambda solution needed (fwd)

lonetwin lonetwin <lonetwin@yahoo.com>
Fri, 26 Apr 2002 11:42:34 +0530 (IST)


Hi again,
	Just to add to my message below, I know I cud do some string
manipulation like
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for user in popList:
	print user+hostname, user
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	but I need to do it the way mentioned because
a) I won't just adding the hosname part, there'll be more to be done
b) I need to refer to the two strings (ie: the created one and the
original one) plenty of times ....and maybe doing the string
manipulation each time may be a __BAD THING__

---------- Forwarded message ----------
Date: Fri, 26 Apr 2002 11:30:54 +0530 (IST)
From: lonetwin <lonetwin@yahoo.com>
To: Python Tutor list <tutor@python.org>
Subject: better map/lambda solution needed

Hi everybody,
     Firstly I'd like to say it's good to be back here, I was working on
 non-python stuff lately (for about 3 months) and so missed all the fun
 happening here :).
 	Anyways, here's a quick question, is there a better way to express
the following code (Note: I'm working on Python1.5). Actually, I know
there should be....but somehow, I'm not seeing the obvious.
Here goes :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> popList = ['steve', 'foo']
>>> hostname = '@mail.foo'
>>> for nick, user in map(None, map(lambda x: x+hostname, popList), popList):
...     print nick, user
...
steve@mail.foo steve
foo@mail.foo foo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have a problem with all that map(None, map(lambda ...) ...) stuff.
Shows that I haven't been using python much, right ?? ;)

Peace
Steve


-- 
"Today's robots are very primitive, capable of understanding only a few
 simple instructions such as 'go left', 'go right', and 'build car'."
 --John Sladek