Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made a little change conditionals.py #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion python_sandbox_finished/conditionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@

# is not
if x is not y:
print(x is not y)
print(x is not y)

x = True

if x == True:
print("The variable x is True")

else:
print("The variable x is false")
22 changes: 22 additions & 0 deletions python_sandbox_finished/map, filter and reduce.py
Original file line number Diff line number Diff line change
@@ -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)