list to tuple question

Mike Ryan miker at 21stcenturyhealth.com
Fri Oct 5 10:56:55 EDT 2001


"Janos Blazi" <jblazi at hotmail.com> wrote in message
news:3bbdc533_6 at news.newsgroups.com...
> I'd like to make a formatted string like this:
>
> s='%s %s %s %s %s %s %s %s %s\n' % (A,)+b+(C,D)
>
> The point is, that b is already a list and this would simplify matters.
Most
> unfortunately (or most obviously for the initiated) I get the error
message
> that a tuple and a list cannot be concatenated. What should I do. I could
> solve the problem by using a for-loop but is it necessary?

Try this:

s = '%s %s %s %s %s %s %s %s %s\n' % ((A,) + tuple(b) + (C, D))

BTW, the other error in your statement was not putting the concatenation
inside of parentheses.  Remember your order of evaluation for operators.
The modulo operator (%) has a higher precedence than the addition (+)
operation.  It suprises me that you actually got the error that you did get.

--

Michael Ryan
Information Services Manager
21st Century Health and Benefits, Inc.




More information about the Python-list mailing list