Don't understand why I am receiving SIGKILL on python -


i'm beginner python , i'm trying make code on code challenge website when given list of integers, returns integer closest zero. if there 2 different integers same difference, e.g. 3 , -3, should return none. (however if number repeated, e.g. 3 , 3, doesn't count that)

i've made code seems work on outside python interpeters, inside website gives error of "process exited prematurely sigkill signal."

on external python interpreter seems return integer i'm looking for

def closest(lst):      ans = list(filter(lambda x: abs(0-x) == min([abs(0-i) in set(lst)]), set(lst)))      return ans[0] if len(ans) < 2 else none 

is there in code causing inefficiency or website?

i suspect coding website testing function passing large generator lst. when program converts set, loads entirety of input memory. if uses memory, process may killed oom killer.

i think following solution ought work. note iterates on lst , doesn't construct other large data structures; state stack variables c , ans. therefore uses constant amount of memory.

def closest(lst):     (c, ans) = (none, none)     in lst:         if (c none) or (abs(i) < abs(c)):             (c, ans) = (i, i)         elif == -1 * c:             ans = none     return ans 

Comments

Popular posts from this blog

The SDK directory does not exist (ubuntu 16.04) (react native) -

python - How to clone or copy a list? -

python - How to use Celery in Tornado with redis as broker and backend? -