Simple problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Angelo Secchi

    Simple problem

    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_'+i ndex


    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

  • Lennart Jonsson

    #2
    Re: Simple problem

    Angelo Secchi <secchi@sssup.i t> wrote in message news:<mailman.7 01.1068719685.7 02.python-list@python.org >...[color=blue]
    > 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_'+i ndex
    >
    >
    > 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[/color]

    As a complement to what others have posted, here is another variant:
    [color=blue][color=green][color=darkred]
    >>> markets = [ 'A', 'B', 'C']
    >>> pippo = map (lambda x:'firm_'+x, markets)
    >>> print pippo[/color][/color][/color]
    ['firm_A', 'firm_B', 'firm_C']

    HTH
    /Lennart

    Comment

    Working...