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
static PyObject *indexerr = NULL; | |
PyObject * | |
PyList_GetItem(PyObject *op, Py_ssize_t i) | |
{ | |
if (!PyList_Check(op)) { | |
PyErr_BadInternalCall(); | |
return NULL; | |
} | |
if (!valid_index(i, Py_SIZE(op))) { |
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
prices = [ | |
("ice cream", 80), | |
("bike", 20000), | |
("water", 30), | |
] | |
sorted_by_price = sorted(prices, key=lambda x: x[1]) | |
print(sorted_by_price) | |
# > [('water', 30), ('ice cream', 80), ('bike', 20000)] |
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
### Use recursive lambda functions to define function with multiple arguments | |
add = lambda x: (lambda y: x + y) | |
print(add(3)(5)) | |
# > 8 | |
### Use normal function to do the same thing | |
def add(x, y): | |
return x + y | |
print(add(3, 5)) |
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
### Build lambda function | |
lambda x: x + 1 | |
### Build lambda function and assign it into one variable | |
add = lambda x: x + 1 | |
print(add(5)) | |
# > 6 | |
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
def dog(): | |
height = 40 | |
def grow_up(): | |
nonlocal height | |
height = height + 1 | |
def show_height(): | |
print("Thanks for making me growing up. I'm now {} meters !!!!".format(height)) |
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
def dog(): | |
height = 40 | |
def grow_up(): | |
nonlocal height | |
height = height + 1 | |
print("Thanks for making me growing up. I'm now {} meters !!!!".format(height)) | |
return grow_up |
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 x | |
x = 10 | |
def add_x(): | |
x = x + 1 | |
if __name__ == "__main__": | |
add_x() |
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
def dog(): | |
height = 40 | |
def grow_up(): | |
height = height + 1 | |
return grow_up | |
if __name__ == "__main__": |
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
def dog(): | |
height = 40 | |
def profile(): | |
print("I'm a dog and my height is {}.".format(height)) | |
return profile | |
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
class Dog: | |
def __init__(self, func): | |
self.talent = func | |
def bark(self): | |
print("Bark !!!") | |
@Dog | |
def dog_can_pee(): |