代码如下:
#encoding=utf-8
print '中国'
#检查序列的成员 in影响性能,而且不能转换为字典或者集合,需要保留原来的顺序
def addUnique(baselist,otherlist):
auxDict=dict.fromkeys(baselist) #唯一化
for item in otherlist:
if item not in auxDict:
baselist.append(item)
auxDict[item] = None #加入key列表
alist=[1,2,3,3,2,1]
print dict.fromkeys(alist)
print alist
addUnique(alist,[1,4])
print alist
打印如下:
中国
{1: None, 2: None, 3: None}
[1, 2, 3, 3, 2, 1]
[1, 2, 3, 3, 2, 1, 4]