On Apr 3, 3:01 pm, "7stud" <[EMAIL PROTECTED]> wrote: > On Apr 3, 12:20 pm, "bahoo" <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I have a list like ['0024', 'haha', '0024'] > > and as output I want ['haha'] > > > If I > > myList.remove('0024') > > > then only the first instance of '0024' is removed. > > > It seems like regular expressions is the rescue, but I couldn't find > > the right tool. > > > Thanks! > > bahoo > > Here are a couple of ways: > > target = "0024" > l = ["0024", "haha", "0024"] > > ------------------------------------ > while(True): > try: > l.remove(target) > except ValueError: > break > > print l > ------------------------------------- > > for index, val in enumerate(l): > if val==target: > del l[index] > > print l
This latter suggestion (with the for loop) seems to be buggy: if there are multiple items in the list "l" equal to "target", then only the first one will be removed! Thanks anyways. -- http://mail.python.org/mailman/listinfo/python-list