# -*- coding: utf-8 -*-
from functools import reduce
def greet(name):
print("hello,"+name+"!")
greet2(name)
print("getting ready to say bye.")
bye()
def greet2(name):
print("how are you "+name+"?")
def bye():
print("ok bye.")
#阶乘
def fact(x):
if x==1:
return 1
else:
return x*fact(x-1)
print(fact(3))
greet("jiawy")
#快排
def quicksort(array):
if len(array)<2:
return array
else:
pivot=array[0]
less=[i for i in array[1:] if i<=pivot]
greater =[i for i in array[1:] if i>pivot]
return quicksort(less)+[pivot]+quicksort(greater)
print(quicksort([10,5,2,3]))
#哈希表
phone_book=dict()
phone_book={}
phone_book["jenny"]=8675309
phone_book["emergency"]=911
print(phone_book["jenny"])
#投票
voted={}
value =voted.get("tom")
def check_voter(name):
if voted.get(name):
print ("kick them out")
else:
voted[name]=True
print("let them out")
check_voter("tom")
arr1=[1,2,3,4,5]
print(reduce(lambda x,y:x+y,arr1))