tuple to string/list
Batista, Facundo
FBatista at uniFON.com.ar
Thu Aug 21 16:09:36 EDT 2003
#- for i in range(len(month)):
#- output="Hits for",month[i], ":" , teller[i]
#- f.write(str(output))
#- f.close()
#-
#- => this produces a tuple:
#- ('Hits for', 'Jan', ':', 0)('Hits for', 'Feb', ':', 2)('Hits for',
#- 'Mar', ':', 3)
#-
#- => whereas I would like the following output:
#- Hits for Jan: 0
#- Hits for Feb: 2
#- Hits for Mar: 3
#-
#- Any easy way of obtaing this output?
Don´t know what´s teller, so I'll assume you need the range(len(month))
situation.
for i in range(len(month)):
output = "Hits for " + month[i] + ": " + teller[i]
f.write(output + "\n") # remember the "\n"
f.close()
More efficient (not adding strings):
for i in range(len(month)):
output = "Hits for %s: %s" % (month[i], teller[i])
f.write(output + "\n") # remember the "\n"
f.close()
My way:
output = ["Hits for %s: %s" % (month[i], teller[i]) for i in
range(len(month))]
f.write("\n".join(output))
f.close()
. Facundo
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
ADVERTENCIA
La información contenida en este mensaje y cualquier archivo anexo al mismo,
son para uso exclusivo del destinatario y pueden contener información
confidencial o propietaria, cuya divulgación es sancionada por la ley.
Si Ud. No es uno de los destinatarios consignados o la persona responsable
de hacer llegar este mensaje a los destinatarios consignados, no está
autorizado a divulgar, copiar, distribuir o retener información (o parte de
ella) contenida en este mensaje. Por favor notifíquenos respondiendo al
remitente, borre el mensaje original y borre las copias (impresas o grabadas
en cualquier medio magnético) que pueda haber realizado del mismo.
Todas las opiniones contenidas en este mail son propias del autor del
mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones
Personales S.A. o alguna empresa asociada.
Los mensajes electrónicos pueden ser alterados, motivo por el cual
Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación
cualquiera sea el resultante de este mensaje.
Muchas Gracias.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030821/fb68b1d9/attachment.html>
More information about the Python-list
mailing list