Skip to content

Instantly share code, notes, and snippets.

View mingrammer's full-sized avatar
🧗
learn, code, and grow

MinJae Kwon (Miti) mingrammer

🧗
learn, code, and grow
View GitHub Profile
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)
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
def save_ranking(**kwargs, *args):
...
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'}
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'}
def save_ranking(*args):
print(args)
save_ranking('ming', 'alice', 'tom', 'wilson', 'roy')
# ('ming', 'alice', 'tom', 'wilson', 'roy')
def save_ranking(first, second=None, third, fourth=None):
...
# 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')
# 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]))
>>> 2 * 3
6
>>> 2 ** 3
8
>>> 1.414 * 1.414
1.9993959999999997
>>> 1.414 ** 1.414
1.6320575353248798