On Sat, Jan 31, 2009 at 9:09 AM, David <ld...@gmx.net> wrote: > 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. <snip>
I'm really not sure if you could. Strings don't support item reassignment, so you can't do it this way: In [1]: x = 'foo bar' In [2]: x[3] = '_' --------------------------------------------------------------------------- TypeError Traceback (most recent call last) C:\Documents and Settings\Wayne\<ipython console> in <module>() TypeError: 'str' object does not support item assignment But there are other string methods available, such as the replace method. http://docs.python.org/library/string.html for the string documentation. HTH, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor