On Thu, Jul 16, 2009 at 5:50 AM, Kent Johnson <ken...@tds.net> wrote:
> On Thu, Jul 16, 2009 at 4:29 AM, Wayne<sri...@gmail.com> wrote:> I have > two different ways I can put _ in the word: > > word = 'cat' > > > > ''.join(list(word)[1] = '_') > > Not in any Python I ever used... > In [1]: word = 'cat' > > In [2]: > > In [3]: ''.join(list(word)[1] = '_') > ------------------------------------------------------------ > File "<ipython console>", line 1 > SyntaxError: keyword can't be an expression (<ipython console>, line 1) <snip> > Um, the second method is faster and has the advantage of working :-) whoops! What I meant to say was something a bit more like: word = list(word) word[1] = '_' word = ''.join(word) But that's a bit harder to put in a timer so I just used ''.join(list('foo')) Evidently my early morning translation for brevity also translated out successful syntax, doh! -Wayne
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor