[mod_python] python print

Jonathan Gardner jgardner at jonathangardner.net
Wed Jun 11 10:31:03 EST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 11 June 2003 10:06, tpc at csua.berkeley.edu wrote:
> curiosity impels me, if list append is most efficient in concatenating to
> the end of a string, how would I use it where I previously had string
> concatenation ?  I can only print out the values
> surrounded by [[''],[''], etc]:
>

Your curiosity served you well. If you missed this point, the whole thing is 
kinda pointless. ;-)

'join' is the answer. You 'join' the list together into a string after you've 
put the list together.

<snip>
> def convert(numbers):
>     w = []
>     for argument in numbers:
>         w.append([dict1[digit] for digit in argument])
> #        w += ''.join([dict1[digit] for digit in argument])
>     return w
>

Change the line:
	return w
to:
	return "".join(w)

This is a demonstration on how join works:
>>> l = ['A', 'B', 'C', 'D']
>>> " - ".join(l)
'A - B - C - D'
>>> "".join(l)
'ABCD'

- -- 
Jonathan Gardner <jgardner at jonathangardner.net>
(was jgardn at alumni.washington.edu)
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+52dXWgwF3QvpWNwRAs5UAKDqSYz3YVMjUYe1OMkQNtbcUM1wowCgjJaH
d8M139orE/YjDJV5optSTn4=
=Mqq5
-----END PGP SIGNATURE-----



More information about the Mod_python mailing list