Simple problem

Lennart Jonsson lennart at kommunicera.umea.se
Thu Nov 13 17:35:29 EST 2003


Angelo Secchi <secchi at sssup.it> wrote in message news:<mailman.701.1068719685.702.python-list at python.org>...
> Hi,
> I'm newby to Python with the following problem.
> In one of my programs I have the following loop:
> 
> for index in markets:
>     pippo='firm_'+index
>     
> 
> where markets is a list ['A','B','C']. In the same loop at each step I
> would like to create a new list with name 'firm_A', 'firm_B' and so on.
> How can I ask to python to do that?
> 
> Thanks.
> Angelo

As a complement to what others have posted, here is another variant:

>>> markets = [ 'A', 'B', 'C']
>>> pippo = map (lambda x:'firm_'+x, markets)
>>> print pippo
['firm_A', 'firm_B', 'firm_C']

HTH
/Lennart




More information about the Python-list mailing list