Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for tup in somelist:
- if determine(tup):
- code_to_remove_tup
- somelist = [x for x in somelist if determine(x)]
- somelist = [x for x in somelist if not determine(x)]
- somelist[:] = [x for x in somelist if not determine(x)]
- from itertools import ifilterfalse
- somelist[:] = list(ifilterfalse(determine, somelist))
- somelist[:] = [tup for tup in somelist if determine(tup)]
- somelist = [tup for tup in somelist if determine(tup)]
- newlist = []
- for tup in somelist:
- # lots of code here, possibly setting things up for calling determine
- if determine(tup):
- newlist.append(tup)
- somelist = newlist
- for tup in somelist[:]:
- # lots of code here, possibly setting things up for calling determine
- if determine(tup):
- newlist.append(tup)
- for i in xrange(len(somelist) - 1, -1, -1):
- if some_condition(somelist, i):
- del somelist[i]
- >>> somelist[:] = filter(lambda tup: not determine(tup), somelist)
- or:
- >>> from itertools import ifilterfalse
- >>> somelist[:] = list(ifilterfalse(determine, somelist))
- for tup in somelist[:]:
- etc....
- >>> list = range(10)
- >>> for x in list:
- ... list.remove(x)
- >>> list
- [1, 3, 5, 7, 9]
- >>> list = range(10)
- >>> for x in list[:]:
- ... list.remove(x)
- >>> list
- []
Add Comment
Please, Sign In to add comment