[Tutor] Best way to replace items in a list.
Alan Gauld
alan.gauld at btinternet.com
Sat Oct 21 00:49:51 CEST 2006
Chris,
> Will that replace the location? or add to it?
>
>> if item in list:
>> loc = list.index(item)
>> list[loc] = str
Jason already showed you the answer, but significantly he also
showed you how to find out for yourself. Use the >>> prompt.
Its what its there for.
For some reason people use the >>> prompt wehen starting out
in Python then seem to forget it exists. But the ability to try out
little bits of code interactively as you develop code is one of
Pythons most powerful features. One that it shares with Lisp
Ruby and Smalltalk but surprisingly few other languages...
For those kinds of quiestions its usually much faster to just
try it than it is to post a question to the list!
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list