Simple problem

A

Angelo Secchi

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
 
L

Lennart Jonsson

Angelo Secchi said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,921
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top