最喜欢用python做这种数据结构类型的操作了
origin = [
('john', 'canada'),
('bob', 'usa'),
('tom', 'usa'),
('alice', 'canada'),
('alan', 'canada'),
('peter', 'uk')
]
temp = []
def detect(t):
if t[1] not in temp:
temp.append(t[1])
return True
return False
print(list(filter(lambda t: detect(t), origin)))
('john', 'canada'),
('bob', 'usa'),
('tom', 'usa'),
('alice', 'canada'),
('alan', 'canada'),
('peter', 'uk')
]
temp = []
def detect(t):
if t[1] not in temp:
temp.append(t[1])
return True
return False
print(list(filter(lambda t: detect(t), origin)))