EDIT
Oh well, I wrote a solution that was pretty the same than one of the Duncan's ones. So I delete what I wrote and I let what I consider to be the best solution, mixing one Duncan's solution and the proposal of martineau (use of any( ) appears to me a lot more preferable to the use of list( ) or a list comprehension as the one I had written; very good idea the any( ), that's better than the complication of importing consume( ) IMO)
def disting(L):
dust,right = [],[]
dustapp = dust.append
rightapp = right.append
any(rightapp(x) if x else dustapp(x) for x in L)
return right,dust
for seq in ((10,None,'a',0,None,45,'qada',False,True,0,456),
[False,0,None,104,True,str,'',88,'AA',__name__]):
yay,nay = disting(seq)
print 'seq == %r\nyay == %r\nnay == %r' % (seq,yay,nay)
print '---------------------------------------'
result
seq == (10, None, 'a', 0, None, 45, 'qada', False, True, 0, 456)
yay == [10, 'a', 45, 'qada', True, 456]
nay == [None, 0, None, False, 0]
---------------------------------------
seq == [False, 0, None, 104, True, <type 'str'>, '', 88, 'AA', '__main__']
yay == [104, True, <type 'str'>, 88, 'AA', '__main__']
nay == [False, 0, None, '']
---------------------------------------
By the way, using any( ) works because rightapp(x)
and dustapp(x)
return None. In case a True or equivalent to True would be returned, the iteration inside any( ) would stop !