fixes some bugs about lib importing

reduce() usage compatibility for Python3
dict.iteritems -> dict.items
library importing issues fixed.