[Tutor] methods split and join in sequence

David ldl08 at gmx.net
Sat Jan 31 16:09:54 CET 2009


Dear list,

many thanks for all your help - much appreciated.
Today I have continued reading Harrington, and produced the following 
code, which works flawlessly.
I wonder, though, how I could join all the supplied words with 
underscores _without_ making use of split first? This I didn't manage.

Thanks for your ideas!

David


'''
convert text with whitespace, supplied by the user,  into a string
joined by underscores.
'''
seq = raw_input("Please write some words: ")
print "You wrote the following words: ", seq
print "The program now joins all words with underscores: ",
seq2 = seq.split()
print '_'.join(seq2)


More information about the Tutor mailing list