Category : lambda

I have a function that should compute an integral, taking in some function as input. I’d like the code to compute a definite integral of: <some function, in terms of x. e.g., 3*x or 3*x*(1-x), etc.> * np.sin(np.pi * x)). I’m using scipy for this: import scipy.integrate as integrate def calculate(a): test = integrate.quad(a*np.sin(np.pi * ..

Read more

grades = [ {"LETTER GRADE": "C"}, {"LETTER GRADE": "A+"}, {"LETTER GRADE": "B"}, {"LETTER GRADE": "A-"}, {"LETTER GRADE": "C-"}, {"LETTER GRADE": "D"}, {"LETTER GRADE": "F"}, {"LETTER GRADE": "B+"}, {"LETTER GRADE": "C+"}, {"LETTER GRADE": "A"}, ] print("Before sorting:") print(grades) print() def lgs(dict): grade = dict["LETTER GRADE"] if len(grade) == 1: return grade + "2" if grade[1] == ..

Read more

I got AWS Lambda with python code which does two things over proxy connection. First: Takes AWS secret value with boto3.client use, where proxies={‘http’=’xx, ‘https’=’xx’} in config (one function) Second: Send files to SFTP with paramiko, socks an socket connection, also with proxy(the same as in first function) set. (another function) During test i noticed ..

Read more

so, I saw someone using the reduce method to do recursion. here is his idea (1,0) , (1,1) , (2,1) , (3,2) , (5,3) which is corresponding 1,1,2,3,5,8,13,21 ……. and the code looks like this def fib_reduce(n): initial =(1,0) dummy = range(n) fib_n = reduce(lambda prev ,b : (prev[0] + prev[1], prev[0]), dummy, initial) return ..

Read more