list to string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lars Behrens

    list to string

    Hi there!

    I need help for cgi-script.

    I've been fiddling around for quite a while, searched through lots of
    doc. But I didn't get it:

    Can someone point me a way to change a list with arbitrary number of
    items to a string :

    vals = ['aaa', 'bbb', 'ccc']
    valstring = 'aaa, bbb, ccc'

    Seems easy at the first glance, but...

    Tia
    Lars

  • Sean Ross

    #2
    Re: list to string

    [color=blue][color=green][color=darkred]
    >>> vals = ['aaa', 'bbb', 'ccc']
    >>> ', '.join(vals)[/color][/color][/color]
    'aaa, bbb, ccc'



    Comment

    • Nicola Mingotti

      #3
      Re: list to string

      Lars Behrens <Spam.Buster@we b.de> writes:[color=blue]
      >
      > Can someone point me a way to change a list with arbitrary number of
      > items to a string :
      >
      > vals = ['aaa', 'bbb', 'ccc']
      > valstring = 'aaa, bbb, ccc'
      >[/color]

      # here you import a lot of functions on strings
      import string

      vals = ['a','b','c']
      valstring = string.join(val s,",")
      [color=blue]
      > Seems easy at the first glance, but...[/color]
      .... it's :)

      bye

      Comment

      • Nick Welch

        #4
        Re: list to string

        On Sat, Sep 06, 2003 at 04:06:52AM +0200, Lars Behrens wrote:[color=blue]
        > Can someone point me a way to change a list with arbitrary number of
        > items to a string :
        >
        > vals = ['aaa', 'bbb', 'ccc']
        > valstring = 'aaa, bbb, ccc'
        >
        > Seems easy at the first glance, but...[/color]
        [color=blue][color=green][color=darkred]
        >>> vals = ['aaa', 'bbb', 'ccc']
        >>> valstring = ", ".join(vals )
        >>> valstring[/color][/color][/color]
        'aaa, bbb, ccc'[color=blue][color=green][color=darkred]
        >>>[/color][/color][/color]

        :)

        HTH,
        --
        Nick Welch aka mackstann | mack @ incise.org | http://incise.org
        The income tax has made more liars out of the American people than golf
        has. Even when you make a tax form out on the level, you don't know
        when it's through if you are a crook or a martyr.
        -- Will Rogers

        Comment

        Working...