Newbie lists question

Tino Lange tl_news at nexgo.de
Thu Jul 4 22:54:04 EDT 2002


Michael Hall wrote:

> selectlist = []
> for last in result:
>   selectlist.append(last)
> 
> produces the result when the list is iterated through and printed,
> which looks something like this:
> 
> ('van Rossum',) ('Wall',) ('Lerdorf',) ('Ousterhout',)

> I know I could probably strip the round brackets and single quotes out
> using a regex, but is there an easier way? Is there something pretty basic
> about lists that I've missed here?

Not about lists but about tuples :-)

Your objects 'last' that you append to selectlist are tuples, not strings.
(You get tuples containing just one element, a string with 'lastname' of 
each MySQL-dataset)

So try:

selectlist = []
for last in result:
   selectlist.append(last[0])

or just (with Python > 2.x)

selectlist = [last[0] for last in result]

Ciao,
  Tino




More information about the Python-list mailing list