list to tuple conversion

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Oct 1 05:10:50 EDT 2008


En Wed, 01 Oct 2008 04:51:33 -0300, sc <nospam at spamhaters.com> escribió:

> Thanx to a recent thread I am able to have a print string
> with a variable number of formatters -- what I now lack for
> the creation of an elegant print statement is a tuple --
> following is the code, the last line of which does not work:
>
> for i in range(1, len(h.m)):
>     k = "r%06d" % i
>     col = len(h.m[k])
>     if col > 2 and h.m[k][0] > " ":
>         print (col * '%-30s') % h.m[k]
> </code>

Another alternative would be:

print ''.join('%-30s' % item for item in h.m[k])

You may need to add square brackets [ ] inside the parenthesis () if your  
Python version is older than 2.5

-- 
Gabriel Genellina




More information about the Python-list mailing list