84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
假设有一个list是[2,1,4,1,5,1,6,1],如果我想统计这个list中有多少个1,以及每个1的位置,应该如何写呢?谢谢~~
认证高级PHP讲师
count count, position index
a = [1,2,3,1] a.count(1) # 2 a.index(1) # 0 [x for x in range(len(a)) if a[x] == 1] # 一次获得所有位置
count count, position index