我是一名热爱编程的开发者,喜欢在这里分享自己编写的代码。
// 原始数组
const array = [1, 2, 2, 3, 4, 4, 5];
// 使用 Set 去重
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // 输出: [1, 2, 3, 4, 5]
from collections import Counter
# 原始列表
my_list = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
# 使用 Counter 统计元素出现次数
count = Counter(my_list)
print(count) # 输出: Counter({4: 4, 3: 3, 2: 2, 1: 1})