If you want to literally remove None objects from a list....(or mutable sequence)

def deNone(alist):
  n=len(alist)
  i=j=0
  while i < n:
    if alist[i] is not None:
      alist[j] = alist[i]
      j += 1
    i += 1
  alist[j:i] = []

blist=[None,1,None,2,None,3,None,None,4,None]
deNone(blist)
print(blist)

# prints [1, 2, 3, 4]

Terry Jan Reedy

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

Reply via email to