Home>Article>Web Front-end> Array deduplication in JavaScript and Python
"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.
>>> 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]
Document
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!