# *arg **kwargs
def greet(farg, *arg):
print ('title: ', farg)
for i in arg:
print('parm ', i)
greet('hello', 'x', 'y', 'z')
def greet_me(**kwargs):
for key, value in kwargs.items():
print('his ',key, ' is', value)
greet_me(age='18', name='hd')
# 生成器
def generator_fun(n=10):
for i in range(n):
yield i
for i in generator_fun(3):
print(i)
def fib(n):
a = 1
b = 1
for i in range(n):
yield a
a, b = b, a+b
for i in fib(5):
print(i)
from collections import defaultdict
from collections import Counter
colours = (('A','yellow'),('B','yellow'),('A','blue'))
result = defaultdict(list)
for name, colour in colours:
result[name].append(colour)
print(result)
print(result['A'])
result_count = Counter(name for name, colour in colours)
print(result_count)
from collections import deque #双端队列
d = deque(range(5))
print(d)
print(d.popleft())
print(d.pop())