1、zip()
>>> a =[one,two,three]
>>> b=[1,2,3]
>>> zipped=zip(a,b)
>>> print(zipped)
<zip object at 0x10396f588>
In python 3, zip() returns an iterable object, so the above example returns an object, not a specific value.
>>> c = zip(a,b)
>>> for value in c:
... print(value)
...
('one', 1)
('two', 2)
('three', 3)
In python2, return the value directly
>>> zipped=zip(a,b)
>>> print(zipped)
...
('one', 1)
('two', 2)
('three', 3)
2、sys.stdout
import sys
f_result=open('result.txt', 'w')
sys.stdout=f_result # print to text
3. The difference between python2 and python3 to judge whether the dictionary has a certain key
‘’‘python2’‘’
def cmpjson(x, y):
if x.has_key('name'):
return x['name'] > y['name']
'''python3'''
def cmpjson(x, y):
if x.__contains__('name'):
return x['name'] > y['name']