diff --git a/python_sandbox_finished/conditionals.py b/python_sandbox_finished/conditionals.py index 7c07182..6667b0e 100644 --- a/python_sandbox_finished/conditionals.py +++ b/python_sandbox_finished/conditionals.py @@ -64,4 +64,12 @@ # is not if x is not y: - print(x is not y) \ No newline at end of file + print(x is not y) + +x = True + +if x == True: + print("The variable x is True") + +else: + print("The variable x is false") diff --git a/python_sandbox_finished/map, filter and reduce.py b/python_sandbox_finished/map, filter and reduce.py new file mode 100644 index 0000000..9853013 --- /dev/null +++ b/python_sandbox_finished/map, filter and reduce.py @@ -0,0 +1,22 @@ +from setuptools import reduce #importing reduce module for using reduce function (Reduce module is default with python) + +l1 = [2,3,4,5,6] + +mapping_the_l1 = list(map(lambda x: x*2, l1)) # MAP FUNCTION APPLIES THE GIVEN COMMAND TO EVERY INDEX OF A LIST +# IN THIS CASE WE ARE MULTIPLYING EVERY CHARACTER IF LIST l1 TO 2 USING LAMBDA FUNCTION + +print(mapping_the_l1) + + +filtering_the_l1 = list(filter(lambda x: x%2 ==0)) #FILTER FUNCTION FILTERS THE LIST ACCORDING TO OUR WISH +# IN THIS CASE WE ARE FILERING THE NUMBER WHICH IS DIVISIBLE BY 2 IN l1. + +print(filtering_the_l1) + +def add(x, y): + return x+y + +reducing_the_l1 = reduce(add, l1) # REDUCE FUNCTION IS USED FOR DOING MATHEMATICAL OPERATIONS IN A LIST +# HERE, WE ARE ADDING ALL THE CHARACTERS THE LIST l1 + +print(reducing_the_l1)