统计列表中[1,20]出现一次和多次的数
dew=[]
import random
for _ in range(20):
dew.append(random.randrange(1,21))
print(dew)
count=[0]*20
for b in dew:
count[b-1]+=1
print(count)
for p in range(len(count)):
if count[p] > 1:
print('{} occurs {}'.format(p+1,count[p]))
for p in range(len(count)):
if count[p] == 1:
print('{} occurs {}'.format(p+1,count[p]))
dew=[]
import random
for _ in range(20):
dew.append(random.randrange(1,21))
print(dew)
count=[0]*20
once=[]
multi=[]
for b in dew:
if count[b-1]:
continue
if dew.count(b) > 1:
multi.append(b)
count[b-1]=dew.count(b)
print('{} ouccur {}'.format(b,count[b-1]))
if dew.count(b) == 1:
once.append(b)
count[b-1]=1
print('{} ouccur {}'.format(b,count[b-1]))
dew=[]
import random
for _ in range(20):
dew.append(random.randrange(1,21))
print(dew)
count=[0]*20
for b in dew:
count[b-1]+=1
for b in range(len(count)):
if count[b] > 1:
print('{} ouccur {}'.format(b+1,count[b]))
elif count[b] == 1:
print('{} occur {}'.format(b+1,count[b]))
dew=[]
import random
for _ in range(20):
dew.append(random.randrange(1,21))
print(dew)
count=[0]*20
once=[]
multi=[]
for b in dew:
if dew.count(b) > 1:
if b not in multi:
multi.append(b)
elif dew.count(b) == 1:
once.append(b)
print('once: {} {}'.format(once,len(once)))
print('mulit: {} {}'.format(multi,len(multi)))
dew=[]
import random
for _ in range(20):
dew.append(random.randrange(1,21))
print(dew)
count=[0]*20
state=[0]*len(dew)
once=[]
multi=[]
for b in range(len(dew)):
if state[b]:
continue
flag=False
for p in range(b+1,len(dew)):
if state[p]:
continue
if dew[b] == dew[p]:
flag = True
state[p]=1
if flag:
multi.append(dew[b])
state[b]=1
else:
once.append(dew[b])
print('once has {},length:{}'.format(once,len(once)))
print('multi has {},length:{}'.format(multi,len(multi)))