473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Removing a particular index from a list

Hi,

list.remove(item) removes the first item from the list, but how do I
say to remove a particular index from a list without using it's value?

Let's say I have 4 items in my list as
>>li = ["sri", "s", "srikanth", "s"]
And if I want to remove the last item ("s"), how do I remove it?
li.remove(-1) doesn't do it. This is my problem.

Thanks,
Srikanth

Mar 22 '07 #1
6 1583
Srikanth wrote:
Hi,

list.remove(item) removes the first item from the list, but how do I
say to remove a particular index from a list without using it's value?

Let's say I have 4 items in my list as
>>>li = ["sri", "s", "srikanth", "s"]

And if I want to remove the last item ("s"), how do I remove it?
li.remove(-1) doesn't do it. This is my problem.
>>li = ["sri", "s", "srikanth", "s"]
del li[-1]
li
['sri', 's', 'srikanth']
>>>
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 22 '07 #2
>>li = ["sri", "s", "srikanth", "s"]
And if I want to remove the last item ("s"), how do I remove it?
li.remove(-1) doesn't do it. This is my problem.

Thanks,
Srikanth
li.pop() will remove the last element

Cyril
Mar 22 '07 #3
Srikanth wrote:
list.remove(item) removes the first item from the list, but how do I
say to remove a particular index from a list without using it's value?

Let's say I have 4 items in my list as
>>>li = ["sri", "s", "srikanth", "s"]

And if I want to remove the last item ("s"), how do I remove it?
li.remove(-1) doesn't do it.
del li[-1]
This is my problem.
This, or not reading the tutorial.

http://docs.python.org/tut/node7.htm...00000000000000

Peter
Mar 22 '07 #4
Thanks Steve, Cyril and Peter.
>
This, or not reading the tutorial.

http://docs.python.org/tut/node7.htm...00000000000000

Peter
I read this 2 months ago and I expected it to be a method of list, but
I sound like I am making an excuse. Thanks a lot.

Regards,
Srikanth

Mar 22 '07 #5
Peter Otten wrote:
Srikanth wrote:
>list.remove(item) removes the first item from the list, but how do I
say to remove a particular index from a list without using it's value?

Let's say I have 4 items in my list as
>>>>li = ["sri", "s", "srikanth", "s"]
And if I want to remove the last item ("s"), how do I remove it?
li.remove(-1) doesn't do it.

del li[-1]
>This is my problem.

This, or not reading the tutorial.
No, that's OUR problem :-)
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Mar 22 '07 #6
Steve Holden wrote:
Peter Otten wrote:
>Srikanth wrote:
>>list.remove(item) removes the first item from the list, but how do I
say to remove a particular index from a list without using it's value?

Let's say I have 4 items in my list as

>li = ["sri", "s", "srikanth", "s"]
And if I want to remove the last item ("s"), how do I remove it?
li.remove(-1) doesn't do it.

del li[-1]
>>This is my problem.

This, or not reading the tutorial.
No, that's OUR problem :-)
And the fact that it's our /self-inflicted/ problem makes it all the more
severe :-)

Peter
Mar 22 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Drew | last post by:
I have a permission tracking app that I am working on, and I have made the insert page for it. I am having issues on how to prevent duplicates from getting entered. Currently the interface for...
3
by: Jeremy Owens-Boggs | last post by:
We are trying to implement a dual list box selection where you have two list boxes, You highlight items in the right side list box, click a button and this moves those items over to the left hand...
3
by: Filippo P. | last post by:
Hi there, I have a menu (Collection) that needs to be trimmed based on security access of the logged user. protected void AdjustMenuBasedOnUserSecurity(Items ItemsList) { foreach (Item i in...
0
by: Adam J. Schaff | last post by:
Hello. I have a custom collection that implements IBindingList (allownew and allowremove are both true). I have bound it to a datagrid. I have add and remove buttons on the screen. I want to...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
5
by: nuffnough | last post by:
This is python 2.4.3 on WinXP under PythonWin. I have a config file with many blank lines and many other lines that I don't need. read the file in, splitlines to make a list, then run a loop...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
5
by: Bart Steur | last post by:
Hi, What's the best way to programmaticly select (click) another listview Item after removing the selected/focused one. using VB2005 Express. Thanks Bart
3
m6s
by: m6s | last post by:
Hello to all, I am having trouble removing an item from list, which the item is a list by itself. <code> for self.line in self.filtered: if self.appid: if self.line <> self.appid: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.