Simple problem
Harvey Thomas
hst at empolis.co.uk
Thu Nov 13 05:43:44 EST 2003
Angelo Secchi wrote
>
> 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
>
Two ways:
pippo = []
for index in markets:
pippo.append('firm_' + index)
or the list comprehension
pippo = ['firm_ + index for index in markets]
_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.
More information about the Python-list
mailing list