**kwargs用法,双星“**”放在字典的前面可以让你将字典的内容作为命名参数传递给函数。字典的键是参数的名字,键的值作为参数的值传递给函数。
一、**kwargs用法
dictionary = {"a":1,"b":2}
def someFunction(a ,b):
print(a + b)
return
someFunction(**dictionary)
二、列表推导式
numbers = [1,2,3,4,5,6,7,8]
evens = [x for x in numbers if x % 2 == 0]
odds = [y for y in numbers if y not in evens]
print(odds)
注意:以下这种用法也是属于列表推导式的变种:
cities = ['西安','北京','秦皇岛','广元','南京']
def vist(city):
print("Welcome"+city)
for city in cities:
vist(city)
>>>Welcome西安
>>>Welcome北京
>>>Welcome秦皇岛
>>>Welcome广元
>>>Welcome南京
三、map常和lambda函数配合使用
x = [1,2,3,4]
y = list(map(lambda x:x*x*x, x))
print(y)
>>>[1, 8, 27, 64]
四、zip() 和 *zip()
keys = ['w','l','m']
values = [4,10,14]
zipped = zip(keys,values)
print(dict(zipped))
>>>{'w': 4, 'l': 10, 'm': 14}
m , n = zip(*zip(keys,values))
print(m,n)
>>>('w', 'l', 'm') (4, 10, 14)
五、Keras有个特别好用的下载文件的方法
from keras import *
from keras.utils import get_file
saved_file_path = get_file(file,url)
六、join()和split()配合使用可以去掉空字符串
print("".join(" 逻辑回归 其实是一种用来做 分类 的模型, \n \t 而不是做 回归 。".split()))
>>>逻辑回归其实是一种用来做分类的模型,而不是做回归。