
code loops through list once and seems to handle all cases (just returns [0] if there's a zero in there etc):
a=[-16,4,16,7,-4]
def getzeroclosest(a):
negmax=None
posmin=None
for n in a:
if n==0:
return [0]
elif n<0:
if negmax==None:
negmax=n
if n>negmax:
negmax=n
elif n>0:
if posmin==None:
posmin=n
if n<posmin:
posmin=n
if -negmax==posmin:
return [posmin,negmax]
elif -negmax<posmin:
return [negmax]
else:
return [posmin]
print getzeroclosest(a)
Thanks for reading

code that I typed with

fingers on

keyboard. Yeah right, there's no self ownership in this totalitarian world, none of those things are mine, we're all slaves.