Guest User

Untitled

a guest
May 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. for tup in somelist:
  2. if determine(tup):
  3. code_to_remove_tup
  4.  
  5. somelist = [x for x in somelist if determine(x)]
  6.  
  7. somelist = [x for x in somelist if not determine(x)]
  8.  
  9. somelist[:] = [x for x in somelist if not determine(x)]
  10.  
  11. from itertools import ifilterfalse
  12. somelist[:] = list(ifilterfalse(determine, somelist))
  13.  
  14. somelist[:] = [tup for tup in somelist if determine(tup)]
  15.  
  16. somelist = [tup for tup in somelist if determine(tup)]
  17.  
  18. newlist = []
  19. for tup in somelist:
  20. # lots of code here, possibly setting things up for calling determine
  21. if determine(tup):
  22. newlist.append(tup)
  23. somelist = newlist
  24.  
  25. for tup in somelist[:]:
  26. # lots of code here, possibly setting things up for calling determine
  27. if determine(tup):
  28. newlist.append(tup)
  29.  
  30. for i in xrange(len(somelist) - 1, -1, -1):
  31. if some_condition(somelist, i):
  32. del somelist[i]
  33.  
  34. >>> somelist[:] = filter(lambda tup: not determine(tup), somelist)
  35. or:
  36. >>> from itertools import ifilterfalse
  37. >>> somelist[:] = list(ifilterfalse(determine, somelist))
  38.  
  39. for tup in somelist[:]:
  40. etc....
  41.  
  42. >>> list = range(10)
  43. >>> for x in list:
  44. ... list.remove(x)
  45. >>> list
  46. [1, 3, 5, 7, 9]
  47.  
  48. >>> list = range(10)
  49. >>> for x in list[:]:
  50. ... list.remove(x)
  51. >>> list
  52. []
Add Comment
Please, Sign In to add comment