Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5 去除列表中的重复元素 # 用字典并保持顺序 #45

Open
coder1688 opened this issue Feb 26, 2018 · 1 comment
Open

5 去除列表中的重复元素 # 用字典并保持顺序 #45

coder1688 opened this issue Feb 26, 2018 · 1 comment

Comments

@coder1688
Copy link

用字典并保持顺序

l1 = ['b','c','d','b','c','a','a']
l2 = list(set(l1)) //应改成 l2={}.fromkeys(l1).keys()
l2.sort(key=l1.index)
print l2

@pusidun
Copy link

pusidun commented Mar 7, 2018

>>> l1=['b','c','d','c','a','a']
>>> l2=list(set(l1))
>>> l2.sort(key=l1.index)
>>> print(l2)
['b', 'c', 'd', 'a']

我在python3上运行没有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants