Re: List operation: Removing an item

2006-04-17 Thread Miguel E
Steven D'Aprano wrote:
> On Sat, 15 Apr 2006 22:39:37 -0600, Miguel E. wrote:
> 
> 
>>I am trying to create a function that removes an item as specified by
>>the user. Apparently, the list operation "del list[:]" deletes the
>>entire list. Below is the sample function.
> 
> 
> If you know the value of the item, and not its position:
> 
> somelist.remove("value")
> 
> This will raise an exception if "value" is not in somelist.
> 

Thank you. That fixed it.

Regards,



-M
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's The Best Editor for python

2006-03-24 Thread Miguel E.
PythonStudent wrote:
> Hi,
> Can one of you say to me what's the best editor for editing the python
> programs ( for linux or windows )


What may be "best" for me, may not necessarily work for you nor anybody
else. Personally, I like to use Kate, Pico, or Joe on Linux, and
Notepad2 or IDLE editor for Windows.

Cheers,


-M
-- 
http://mail.python.org/mailman/listinfo/python-list


List operation: Removing an item

2006-04-15 Thread Miguel E.
Hi,

I've been (self) studying Python for the past two months and I have had
no background in OOP whatsoever.

I was able to write an interactive program that randomly selects an item
 from a list. From a Main Menu, the user has the option to add items to
an empty list, show the list, run the random selector, and of course
quit the program. The program also complains if a user tries to add an
item that is already in the list prompting the user to enter another item.

I am trying to create a function that removes an item as specified by
the user. Apparently, the list operation "del list[:]" deletes the
entire list. Below is the sample function.

Any ideas, suggestions, or tips on the list operation I should be using,
or a better way of writing this?

TIA





shopList = ['eggs', 'milk', 'bread', 'juice', 'fruit', 'deli']

def removeItem():
   "Remove an item from the list"
   print
   for items in shopList:
  print items
   print
   dlete = raw_input("Enter the item you want to remove: ")
   print
   for item in shopList:
  if dlete in shopList:
 del shopList[:]  # <--What is the correct function to use?
 print "%s has been removed" % dlete
 print "The new list is now", shopList
  else:
 print "Item is not in the list"
-- 
http://mail.python.org/mailman/listinfo/python-list