![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2008
Posts: 2
Rep Power: 0
![]() |
Deleting Items from Lists
I have a small problem with lists in python. I need ot know the best way to effectively delete an item from a list. For example, take the following list:
list = ["One", "Two", "Three", "Four"] I want to delete, say, the number two. What i currently do is: count = -1 for number in list: count +=1 if number = "Two": break del list[count] It works for me, but i'm wondering if there is a less clunky way to perform the same operation. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Re: Deleting Items from Lists
Python Syntax (Toggle Plain Text)
['One', 'Three', 'Four']A fast way you could have found this answer is by printing the following in the Python command line: mylist = [] dir(mylist) help(mylist) |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2008
Posts: 2
Rep Power: 0
![]() |
Re: Deleting Items from Lists
thank you. I'm new to python so i dont know much. I found the function remove, thanks again.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pointers and Linked Lists | BstrucT | C | 8 | Feb 11th, 2008 2:33 AM |
| Sorting integer lists | sixstringartist | Python | 4 | Dec 4th, 2007 2:27 PM |
| Linked Lists | Eric the Red | C++ | 6 | Mar 19th, 2006 12:47 AM |
| Nested Lists | Mjordan2nd | Python | 2 | Oct 22nd, 2005 3:41 PM |
| javascript: retrieve datagrid checked items in confirm box | sbells | JavaScript and Client-Side Browser Scripting | 4 | Aug 7th, 2005 1:31 PM |