[Tutor] elegant way to turn list into string?

Max Russell max_russell2000 at yahoo.co.uk
Sat May 7 10:46:46 CEST 2005


Hello-

I've started writing a suite of tools to help me do
Crypto puzzles (slowly...) My first snippet of code
allos me to print out a Caesar shifting alphabet, as I
tend to write them out by hand; which is a waste of
time.

alph =
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
print "\n"
print alph
print "\n"
x = 1
while x < 26:
    alph.append(alph.pop(0))
    print alph
    print "\n"
    x += 1


anyway- I don't like the output which come in the
form:
['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', 'a']


What I'd like to do is take my list and turn it into a
string, which looks neater when printed.

I've tried using join() but that didn't work, can
anyone give me a pointer here?

the other method I've used was dealing with a string
directly:
alph = 'abcdefghijklmnopqrstuvwxyz'
print alph
#print "\n"

x = 1

while x < 26:
    new_alph = alph[1:] + alph[:1]
    print new_alph
    print "\n"
    x += 1

But this has the drawback of not progressing with my
newly create alphabet, it just returns:
abcdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyza


bcdefghijklmnopqrstuvwxyza

etc...


HELP!!

thanks
Max



	
	
		
___________________________________________________________ 
Yahoo! Messenger - want a free and easy way to contact your friends online? http://uk.messenger.yahoo.com


More information about the Tutor mailing list