Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Moving Places, Subtracting from slices/lists

Reply
Thread Tools

Moving Places, Subtracting from slices/lists

 
 
Mark Sargent
Guest
Posts: n/a
 
      06-02-2005
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)
....
>>> hotcat

['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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Moving Estimate, Local Movers, Long Distance Moving, PackingSupplies, Storage Rental, Home Moving, Apartment Moving, Office Moving,Commercial Moving linkswanted ASP .Net 0 01-06-2008 04:45 AM
AddDays exception when subtracting value patrick ASP .Net 2 12-23-2005 06:09 PM
Re: Moving Places, Subtracting from slices/lists Mark Sargent Python 4 06-03-2005 03:50 PM
subtracting days from date =?Utf-8?B?TWFubnkgQ2hvaGFu?= ASP .Net 5 11-09-2004 01:25 AM
subtracting two dates to get number of days between Brian Henry ASP .Net 6 11-19-2003 09:50 PM



Advertisments