Newbie question: how to join a list of elements of user-defined types?

holger krekel pyth at devel.trillke.net
Mon Apr 29 22:16:58 EDT 2002


On Mon, Apr 29, 2002 at 07:02:05PM -0700, Cliff Wells wrote:
> On 29 Apr 2002 18:54:12 -0700
> Fortepianissimo wrote:
> 
> > This question is so fundamental that I strongly suspect it's already
> > answered - ig that's the case, please forgive this poor newbie, for he
> > has done some work searching over Python FAQ and Google.
> > 
> > Basically I want to have a subclass of list, like
> > 
> > class MyList (list):
> >     ...
> > 
> > then I want to
> > 
> > l=MyList()
> > ... do stuff to fill l
> > s=" ".join(l)
> 
> s = " ".join([str(i) for i in l])

or you can use:

" ".join(map(str, l))

#map applies the function 'str' to each element and returns the results
#in a list 

have fun,

    holger





More information about the Python-list mailing list