Equivalent 2->> print '%d %d' %(l[i], for i in range(2))?
Carsten Gaebler
cg at schlund.de
Thu May 17 11:12:32 EDT 2001
Jorn Verwey wrote:
>
> How can I avoid typing %(l[0],l[1]) in the following case?
> ->> l=[4,14]
> ->> print '%d %d' %(l[0],l[1])
>
> would like something more in the line of:
>
> ->> print '%d %d' %(l[i], for i in range(2))
>
> for longer lists.
If l contains integers and strings only, you could say:
print " ".join(map(str, l))
But what if l == [4, 3.14159, 14] and one would like to
print "%d %.3f %d" % <something>
???
Any ideas?
cg.
More information about the Python-list
mailing list