Moving Places, Subtracting from slices/lists

M

Mark Sargent

Hi All,

playing around with the tut now. How can I get this code to remove the
original instance of 'roof'.?
>>> hotcat = ['Cat', 'roof', 'on', 'a', 'hot', 'tin']
>>> for x in hotcat[:]:
.... if x == 'roof': hotcat.insert(6,x)
....['Cat', 'roof', 'on', 'a', 'hot', 'tin', 'roof']

Perhaps a replace or something after the 2nd line of the for function.?
>>> hotcat = ['Cat', 'roof', 'on', 'a', 'hot', 'tin']
>>> for x in hotcat[:]:
.... if x == 'roof': hotcat.insert(6,x)
.... hotcat[x:len(x)] = []
....
Traceback (most recent call last):
File "<stdin>", line 3, in ?
TypeError: slice indices must be integers

I feel I'm close to it.

Cheers.

Mark Sargent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top