This file contains hidden or 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
headers = { | |
'Accept': 'text/plain', | |
'Content-Length': 348, | |
'Host': 'http://mingrammer.com' | |
} | |
def pre_process(**headers): | |
content_length = headers['Content-Length'] | |
print('content length: ', content_length) | |
This file contains hidden or 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
from functools import reduce | |
primes = [2, 3, 5, 7, 11, 13] | |
def product(*numbers): | |
p = reduce(lambda x, y: x * y, numbers) | |
return p | |
product(*primes) | |
# 30030 |
This file contains hidden or 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 save_ranking(**kwargs, *args): | |
... |
This file contains hidden or 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 save_ranking(*args, **kwargs): | |
print(args) | |
print(kwargs) | |
save_ranking('ming', 'alice', 'tom', fourth='wilson', fifth='roy') | |
# ('ming', 'alice', 'tom') | |
# {'fourth': 'wilson', 'fifth': 'roy'} |
This file contains hidden or 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 save_ranking(**kwargs): | |
print(kwargs) | |
save_ranking(first='ming', second='alice', fourth='wilson', third='tom', fifth='roy') | |
# {'first': 'ming', 'second': 'alice', 'fourth': 'wilson', 'third': 'tom', 'fifth': 'roy'} |
This file contains hidden or 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 save_ranking(*args): | |
print(args) | |
save_ranking('ming', 'alice', 'tom', 'wilson', 'roy') | |
# ('ming', 'alice', 'tom', 'wilson', 'roy') |
This file contains hidden or 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 save_ranking(first, second=None, third, fourth=None): | |
... |
This file contains hidden or 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
# A function that shows the results of running competitions consisting of 2 to 4 runners. | |
def save_ranking(first, second, third=None, fourth=None): | |
rank = {} | |
rank[1], rank[2] = first, second | |
rank[3] = third if third is not None else 'Nobody' | |
rank[4] = fourth if fourth is not None else 'Nobody' | |
print(rank) | |
# Pass the 2 positional arguments | |
save_ranking('ming', 'alice') |
This file contains hidden or 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
# Initialize the zero-valued list with 100 length | |
zeros_list = [0] * 100 | |
# Declare the zero-valued tuple with 100 length | |
zeros_tuple = (0,) * 100 | |
# Extending the "vector_list" by 3 times | |
vector_list = [[1, 2, 3]] | |
for i, vector in enumerate(vector_list * 3): | |
print("{0} scalar product of vector: {1}".format((i + 1), [(i + 1) * e for e in vector])) |
This file contains hidden or 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
>>> 2 * 3 | |
6 | |
>>> 2 ** 3 | |
8 | |
>>> 1.414 * 1.414 | |
1.9993959999999997 | |
>>> 1.414 ** 1.414 | |
1.6320575353248798 |