numbers = [2, 2, 3, 3, 4, 1]
new = list(OrderedDict.fromkeys(numbers).keys())
print(new)
[2, 3, 4, 1]
统计列表中元素出现的次数...2, 3, 1, 2, 3, 2, 2, 3, 4, 5, 1]
print(Counter(numbers))
Counter({2: 4, 1: 3, 3: 3, 4: 1, 5: 1})
统计列表中出现次数最多的元素...1
numbers = [1, 2, 3, 1, 2, 3, 2, 2, 3, 4, 5, 1]
print(max(set(numbers), key = numbers.count))
2
统计列表中出现次数最多的元素...2, 3, 1, 2, 3, 2, 2, 3, 4, 5, 1]
cnt = Counter(numbers)
print(cnt.most_common(1))
[(2, 4)]
如何在一个列表中插入另一个列表...[2.3, 2.5]
numbers[3:3] = inserts
print(numbers)
[0, 1, 2, 2.3, 2.5, 3, 4, 5, 6, 7, 8, 9]
如何判断一个列表中的元素是否在另一个列表中