[Tutor] printing columns
Kalle Svensson
kalle@lysator.liu.se
Fri, 26 Jul 2002 03:16:47 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[Rob]
> Actually, what I had in mind was to have output I could paste
> directly into a C++ header file. The output from my original code
> should compile without error, but I thought it would be a nice touch
> to display it in pretty columns.
Something like
print "#define ROB_%s%s%s" % (item, " " * (20 - len(item)), myInt)
maybe?
Maybe 20 is to much or too little. First, do something like
lens = [len(x) for x in menuItems]
lens.sort()
maxlen = lens[-1]
and then use (maxlen + 1) instead of 20 above.
If you had a function sort() like this:
def sort(lst):
x = lst[:]
x.sort()
return x
the second code snippet could be written
maxlen = sort([len(x) for x in menuItems])[-1]
as well.
Peace,
Kalle
- --
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>
iD8DBQE9QKL0dNeA1787sd0RAh9cAKCaT2tXYjaN3oSqWHut+gryHDCHXACfXcO5
31sY0qiD9pOFX0ltxtSE53k=
=DQmR
-----END PGP SIGNATURE-----