Home>Article>Web Front-end> Array deduplication in JavaScript and Python

Array deduplication in JavaScript and Python

小云云
小云云 Original
2018-02-23 14:11:52 1735browse

"Array deduplication" is a commonly used operation in practical applications, and the probability of appearing in interview questions is also very high. Today I will briefly describe the method of array deduplication in Python and JavaScript. I hope it can help everyone.

Python array deduplication

>>> a = [9,8,7,9,7,1,2,1,2,5,3] >>> new_a = list(set(a)) >>> new_a [1, 2, 3, 5, 7, 8, 9] #此时new_a未保持原有的顺序,对new_a进行排序 >>> new_a.sort(key = a.index) >>> new_a [9, 8, 7, 1, 2, 5, 3]

JavaScript array deduplication

    Document  

Array deduplication in JavaScript and Python

Related recommendations:

Detailed examples of several ideas for deduplication in JavaScript arrays

Sharing of several methods for deduplication in JavaScript arrays

JS is simple Analysis of methods to achieve array deduplication

The above is the detailed content of Array deduplication in JavaScript and Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn