View lambda-2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using lambda function inside filter function | |
drinks = ['beer', 'beer', 'milk', 'beer'] | |
print(list(filter(lambda drink: (drink == 'beer'), drinks))) | |
# output: ['beer', 'beer', 'beer'] |
View lambda-2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using lambda function inside filter function | |
drinks = ['beer', 'beer', 'milk', 'beer'] | |
print(list(filter(lambda drink: (drink == 'beer'), drinks))) | |
# output: ['beer', 'beer', 'beer'] |
View lambda-1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create grill function receive 1 argument | |
grill = lambda food: "grilled " + food | |
print(grill('beef')) | |
# output: grilled beef | |
# create cook function receive 2 arguments | |
cook = lambda cook, food: cook + " " + food | |
print(cook("boil", "egg")) | |
# output: boil egg |
View python-scope-explain.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# global scope | |
outer = "eggshell" | |
def egg(): | |
# enclosing scope | |
middle = "egg white" | |
def inner_egg(): | |
# local scope |
View coverage-metrics-2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const doYouLikeDog = (answer) => { | |
return answer === true ? "you like dogs." : answer === false ? "you don't like dogs." : "you didn't answer my question." | |
} | |
test('pass true on doYouLikeDog()', () => { | |
expect(doYouLikeDog(true)).toBe("you like dogs."); | |
}); | |
test('pass false on doYouLikeDog()', () => { | |
expect(doYouLikeDog(false)).toBe("you don't like dogs."); |
View coverage-metrics-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const doYouLikeDog = (answer) => { // cover | |
if (answer === true) return "you like dogs." // cover | |
else if (answer === false) return "you don't like dogs." // cover | |
else return "you didn't answer my question." // not cover | |
} // cover | |
//----------------------------------- | |
test('pass true on doYouLikeDog()', () => { | |
expect(doYouLikeDog(true)).toBe("you like dogs."); |
View convert-numpy-array-to-list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npArrData = np.array([1, 2, 3]) | |
listData = npArrData.tolist() | |
print("npArrData: ", type(npArrData), ": ", npArrData) | |
print("listData:", type(listData), ": ", listData) | |
# Output | |
# npArrData: <class 'numpy.ndarray'> : [1 2 3] | |
# listData: <class 'list'> : [1, 2, 3] |
View convert-list-to-numpy-array.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listData = [1, 2, 3] | |
npArrData = np.asarray(listData) | |
print("listData:", type(listData), ": ", listData) | |
print("npArrData: ", type(npArrData), ": ", npArrData) | |
# Output | |
# listData: <class 'list'> : [1, 2, 3] | |
# npArrData: <class 'numpy.ndarray'> : [1 2 3] |
View numpy-multi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
floatArr = np.random.rand(2, 4) | |
intArr = np.random.randint(100, size=(2, 4)) | |
print("floatArr: \n" + str(floatArr)) | |
print("\nintArr: \n" + str(intArr)) | |
multArr = np.multiply(floatArr, intArr) | |
print("\nmultArr: \n" + str(multArr)) |
View numpy-zero-to-one.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np.random.rand(2,4) | |
# Output | |
# array([[0.62998756, 0.59149609, 0.57944416, 0.485989 ], | |
# [0.72946946, 0.47362045, 0.14221045, 0.27405028]]) |
NewerOlder