From 3431157c1a4e5cb0c74eaa0b4281d790aa74f1c4 Mon Sep 17 00:00:00 2001 From: rakesh Date: Mon, 30 Dec 2019 23:34:41 +0530 Subject: [PATCH] lambda function --- autoGUI/tempCodeRunnerFile.py | 13 +++++++++++++ fileHandling/Bulk_Image_Resizer.py | 2 +- functions/lambda_function.py | 14 ++++++++------ functions/python_kwargs.py | 11 +++++++++++ functions/tempCodeRunnerFile.py | 22 ++++++++++------------ functions/variable_parameter.py | 14 ++++++++++++++ numpy/sumOfDD.py | 2 -- 7 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 autoGUI/tempCodeRunnerFile.py create mode 100644 functions/python_kwargs.py create mode 100644 functions/variable_parameter.py diff --git a/autoGUI/tempCodeRunnerFile.py b/autoGUI/tempCodeRunnerFile.py new file mode 100644 index 0000000..55c5890 --- /dev/null +++ b/autoGUI/tempCodeRunnerFile.py @@ -0,0 +1,13 @@ +# purpose : Program to check mouse position on the move +# author : rakesh kumar +# licence : MIT +import pyautogui +print("Press CTRL+C to stop") +try: + while True: + x,y = pyautogui.position() + positionStr = "X :"+str(x).rjust(4) +" Y :"+ str(y).rjust(4) + print(positionStr, end='') + print('\b' * len(positionStr), end='', flush=True) +except KeyboardInterrupt: + print("\n Done") \ No newline at end of file diff --git a/fileHandling/Bulk_Image_Resizer.py b/fileHandling/Bulk_Image_Resizer.py index 019ef44..19bbc59 100644 --- a/fileHandling/Bulk_Image_Resizer.py +++ b/fileHandling/Bulk_Image_Resizer.py @@ -20,7 +20,7 @@ def small(source,target,original): dest = target + '\\' +original with open(original, 'r+b') as f: with Image.open(f) as image: - cover = resizeimage.resize_cover(image, [900, 450], validate=False) + cover = resizeimage.resize_cover(image, [960, 640], validate=False) cover.save(dest, image.format) def deleteFiles(): diff --git a/functions/lambda_function.py b/functions/lambda_function.py index 44492c0..26a61e1 100644 --- a/functions/lambda_function.py +++ b/functions/lambda_function.py @@ -1,8 +1,10 @@ -#program to define lambda function in python +# program to define lambda function in python -f = lambda x : x**2 -#lambda function with map() function -l1=[1,2,4,5,6,7,78,7,4,34,4,14,44,4,4] -result = map(f,l1) -print(result) \ No newline at end of file +def f(x): return x**2 + + +# lambda function with map() function +l1 = [1, 2, 4, 5, 6, 7, 78, 7, 4, 34, 4, 14, 44, 4, 4] +result = list(map(f, l1)) +print(result) diff --git a/functions/python_kwargs.py b/functions/python_kwargs.py new file mode 100644 index 0000000..2966124 --- /dev/null +++ b/functions/python_kwargs.py @@ -0,0 +1,11 @@ +# python program to demonstrate the use of kwargs arguments in pyhon +# made by : rakesh kumar + + +def sum_kwargs(**kwargs): + for x, y in kwargs.items(): + print('{} and its valiue {}'.format(x, y)) + + +if __name__ == "__main__": + sum_kwargs(name='rakesh', school='DAV', salary=50000) diff --git a/functions/tempCodeRunnerFile.py b/functions/tempCodeRunnerFile.py index aa8cb93..f3b3fc6 100644 --- a/functions/tempCodeRunnerFile.py +++ b/functions/tempCodeRunnerFile.py @@ -1,12 +1,10 @@ -def check_prime(n): - flag = True - for x in range(2, n//2): - if n % x == 0: - flag = False - - return flag - -if __name__ == "__main__": - n = int(input('Enter any integer number : ')) - result = check_prime(n) - print("Prime Number " if (result) else '"Not prime Number') \ No newline at end of file +# program to define lambda function in python + + +def f(x): return x**2 + + +# lambda function with map() function +l1 = [1, 2, 4, 5, 6, 7, 78, 7, 4, 34, 4, 14, 44, 4, 4] +result = map(f, l1) +print(result) diff --git a/functions/variable_parameter.py b/functions/variable_parameter.py new file mode 100644 index 0000000..1c6c50d --- /dev/null +++ b/functions/variable_parameter.py @@ -0,0 +1,14 @@ +# function to demonstrate the workin of args and kwards paramater +# made by : rakesh kumar + + +def sum_values(*args): + sum = 0 + for x in args: + sum += x + return sum + + +if __name__ == "__main__": + res = sum_values(1, 2, 3, 4, 5, 6, 7, 8, 9) + print('Sum of values :', res) diff --git a/numpy/sumOfDD.py b/numpy/sumOfDD.py index 20253b8..006f7de 100644 --- a/numpy/sumOfDD.py +++ b/numpy/sumOfDD.py @@ -3,5 +3,3 @@ a = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)]) b = np.sum(a, 1) print(b) - -`` \ No newline at end of file