list = [1, 2, 3, 4,] [function_1(i) for i in list] so I have a function (with a condition as above) -- the intent is to apply that function to each number in a list (and get a new list with the result). Getting stuck here with error: "TypeError: '<' not supported between instances of 'list' and 'int'"
all help appreciated sorry was trying to recreate in a generic way when I'm getting error in a larger file. added a few steps and am now getting error again:
def function_1(x):
    if x < 0:
        return -1000000000
    else:
        return (x ** (1-2)-1)/(1-2)
my_list = [1.064, .4546, .998, .777,]
my_list2 = [2, 3, -5]
my_list3 = []
for x in my_list2:
    my_list3.append([x * i for i in my_list])
print([function_1(i) for i in my_list3])
  
Output:
runfile('C:/Users/xxxxx/Documents/untitled1.py', wdir='C:/Users/xxxxx/Documents') Traceback (most recent call last): File "<ipython-input-120-55d0d62f9a9e>", line 1, in <module> runfile('C:/Users/ssxxxx/Documents/untitled1.py', wdir='C:/Users/xxxxx/Documents') File "C:\Users\xxxxx\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile execfile(filename, namespace) File "C:\Users\xxxx\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/xxxx/Documents/untitled1.py", line 22, in <module> print([function_1(i) for i in my_list3]) File "C:/Users/xxxx/Documents/untitled1.py", line 22, in <listcomp> print([function_1(i) for i in my_list3]) File "C:/Users/xxxx/Documents/untitled1.py", line 10, in function_1 if x < 0: TypeError: '<' not supported between instances of 'list' and 'int'
If you can't explain it to a six year old, you don't understand it yourself , Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs