1、对象计数collections、np.unique
from collections import Counter
colors = ['red', 'blue', 'red', 'green', 'blue', 'blue']
c = Counter(colors)
print (dict(c))
import numpy as np
a = np.array([0, 3, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 1, 3, 4])
unique, counts = np.unique(a, return_counts=True)
dict(zip(unique, counts))
2、多个对象迭代itertools.chain
from itertools import chain
a = [1, 2, 3, 4]
b = ["x","y"]
for x in chain(a, b):
print(x)