321123
发表于 2018-1-7 12:04:32
或者把for循环里面的部分变为:list3=list(set(list2))
list3.sort()
yjsx86
发表于 2018-1-8 04:21:07
l = [
12, 1, 3, 19, 0, 1, 16, 8, 19, 10, 6, 10, 0, 4, 3, 18, 2, 18, 17, 6, 16,
19, 12, 18, 4, 4, 16, 12, 13, 11, 0, 0, 12, 7, 10, 2, 7, 12, 4, 18, 13, 18,
16, 17, 14, 12, 1, 12, 4, 14, 8, 18, 4, 12, 10, 1, 18, 7, 2, 9, 3, 11, 12,
2, 9, 13, 12, 18, 15, 1, 9, 5, 11, 6, 12, 9, 16, 14, 18, 0, 15, 4, 17, 5,
1, 13, 0, 10, 0, 6, 16, 15, 3, 16, 20, 18, 4, 18, 16, 3
]
d = dict.fromkeys(set(l), 0)
rs = []
for x in l:
d += 1
for k, v in d.items():
rs.append()
print(rs)
我也爱鱼c
发表于 2018-1-8 19:25:40
list1 =
list_ = []
list4 = []
def count_(i):
for i in list1:
a = list()
list_.append(a)
list_.sort()
list2 = list_
for n in list2:
if n not in list4:
list4.append(n)
return list4
count1 = count_(12)
print(count1)
用的最笨的方法,回复只是先看看其他大神的答案
我也爱鱼c
发表于 2018-1-8 19:29:11
在哪里看最佳答案?
lihw
发表于 2018-1-8 20:20:01
list1 = [12, 1, 3, 19, 0, 1, 16, 8, 19, 10, 6, 10, 0, 4, 3, 18,
2, 18, 17, 6, 16, 19, 12, 18, 4, 4, 16, 12, 13, 11, 0,
0, 12, 7, 10, 2, 7, 12, 4, 18, 13, 18, 16, 17, 14, 12, 1,
12, 4, 14, 8, 18, 4, 12, 10, 1, 18, 7, 2, 9, 3, 11, 12, 2,
9, 13, 12, 18, 15, 1, 9, 5, 11, 6, 12, 9, 16, 14,
18, 0, 15, 4, 17, 5, 1, 13, 0, 10, 0, 6, 16, 15,
3, 16, 20, 18, 4, 18, 16, 3]
list2=[]
list3=[]
n=0
list2=set(list1)
for i in list2:
n=list1.count(i)
list3.append()
print(list3)
mjhpython
发表于 2018-1-8 20:57:28
l_chongdu = []
l = []
l1 =
for num in l1:
if num not in l_chongdu:
l_chongdu.append(num)
l.append()
print sorted(l)
sunnychou
发表于 2018-1-10 11:19:58
list1 = [12, 1, 3, 19, 0, 1, 16, 8, 19, 10, 6, 10, 0, 4, 3, 18, 2, 18, 17,
6, 16, 19, 12, 18, 4, 4, 16, 12, 13, 11, 0, 0, 12, 7, 10, 2, 7, 12, 4, 18, 13, 18, 16,
17, 14, 12, 1, 12, 4, 14, 8, 18, 4, 12, 10, 1, 18, 7, 2, 9, 3, 11, 12, 2, 9, 13, 12, 18,
15, 1, 9, 5, 11, 6, 12, 9, 16, 14, 18, 0, 15, 4, 17, 5, 1, 13, 0, 10, 0, 6, 16, 15, 3, 16, 20, 18, 4, 18, 16, 3]
a = collections.Counter(list1)
c =
b =
a = list(zip(c, b))#实现排序,根据key值排序
a.sort()
print()
vite
发表于 2018-1-10 13:30:55
list1 = [12, 1, 3, 19, 0, 1, 16, 8, 19, 10, 6, 10, 0, 4, 3,
18, 2, 18, 17, 6, 16, 19, 12, 18, 4, 4, 16, 12, 13, 11, 0, 0,
12, 7, 10, 2, 7, 12, 4, 18, 13, 18, 16, 17, 14, 12, 1, 12, 4,
14, 8, 18, 4, 12, 10, 1, 18, 7, 2, 9, 3, 11, 12, 2, 9, 13, 12,
18, 15, 1, 9, 5, 11, 6, 12, 9, 16, 14, 18, 0, 15, 4, 17, 5, 1,
13, 0, 10, 0, 6, 16, 15, 3, 16, 20, 18, 4, 18, 16, 3]
list2 = [ for a in range (max(list1)+1) if a in list1 ]
lampard0810
发表于 2018-1-10 14:33:30
list1 = [12, 1, 3, 19, 0, 1, 16, 8, 19, 10, 6, 10, 0, 4, 3, 18, 2, 18, 17, 6,\
16, 19, 12, 18, 4, 4, 16, 12, 13, 11, 0, 0, 12, 7, 10, 2, 7, 12, 4, \
18, 13, 18, 16, 17, 14, 12, 1, 12, 4, 14, 8, 18, 4, 12, 10, 1, 18, 7,\
2, 9, 3, 11, 12, 2, 9, 13, 12, 18, 15, 1, 9, 5, 11, 6, 12, 9, 16, 14,\
18, 0, 15, 4, 17, 5, 1, 13, 0, 10, 0, 6, 16, 15, 3, 16, 20, 18, 4, \
18, 16, 3]
result = []
list1_differ = list(set(list1))#去掉列表中的重复项
list1_differ.sort()#对新生成的列表进行排序
for each in list1_differ:
result.append()
print(result)
yun212
发表于 2018-1-10 15:48:09
111111111
likesunshine
发表于 2018-1-10 16:21:40
想知道代码
wojiaodabai
发表于 2018-1-10 16:26:40
list1 =
myset=set(list1)
list2=[[] for x in range(len(myset))]
for i in myset:
list2.append()
print(list2)
一绿一整周
发表于 2018-1-10 16:52:21
list1 = [12, 1, 3, 19, 0, 1, 16, 8, 19, 10,
6, 10, 0, 4, 3, 18, 2, 18, 17, 6,
16, 19, 12, 18, 4, 4, 16, 12, 13,
11, 0, 0, 12, 7, 10, 2, 7, 12, 4,
18, 13, 18, 16, 17, 14, 12, 1, 12,
4, 14, 8, 18, 4, 12, 10, 1, 18, 7,
2, 9, 3, 11, 12, 2, 9, 13, 12, 18,
15, 1, 9, 5, 11, 6, 12, 9, 16, 14,
18, 0, 15, 4, 17, 5, 1, 13, 0, 10,
0, 6, 16, 15, 3, 16, 20, 18, 4, 18, 16, 3]
print(len(list1))
print(max(list1))
list2_d=
for l in range(0,max(list1)+1):
n=0
for i in range(0,len(list1)):
if list1 == l:
n=n+1
else :
n=n
list2_d=list()
if l !=20:
list2_d.append()
else:
break
print(list2_d)
一绿一整周
发表于 2018-1-10 17:04:58
list1 = [12, 1, 3, 19, 0, 1, 16, 8, 19, 10,
6, 10, 0, 4, 3, 18, 2, 18, 17, 6,
16, 19, 12, 18, 4, 4, 16, 12, 13,
11, 0, 0, 12, 7, 10, 2, 7, 12, 4,
18, 13, 18, 16, 17, 14, 12, 1, 12,
4, 14, 8, 18, 4, 12, 10, 1, 18, 7,
2, 9, 3, 11, 12, 2, 9, 13, 12, 18,
15, 1, 9, 5, 11, 6, 12, 9, 16, 14,
18, 0, 15, 4, 17, 5, 1, 13, 0, 10,
0, 6, 16, 15, 3, 16, 20, 18, 4, 18, 16, 3]
list2_d =
for i in range(max(list1)):
m = list1.count(i)
list2_d=list()
if i != 20:
list2_d.append()
else:
pass
print(list2_d)
Jons
发表于 2018-1-10 17:32:48
list1 =
#先去重函数用 list(set(list1)) 排序函数用sorted()结果输出结果是:
lists = sorted(list(set(list1)))
listData = []
for i,n in enumerate(lists):
#查询有个值在列表中出现的次数函数
listData.append()
print('输出结果是:',listData)
#输出结果是: [, , , , , , , , , , , , , , , , , , , , ]
wenjiew
发表于 2018-1-10 17:48:24
本帖最后由 wenjiew 于 2018-1-10 17:49 编辑
from collections import defaultdict
def solutions(list1):
list2 = defaultdict(int)
for elements in list1:
list2 += 1
return
wenjiew
发表于 2018-1-10 17:49:22
wenjiew 发表于 2018-1-10 17:48
def solutions(list1):
list2 = defaultdict(int)
for elements in list1:
在开头加一个from collections import defaultdict
张仙东
发表于 2018-1-10 18:57:22
list1 = [12, 1, 3, 19, 0, 1, 16, 8, 19, 10, 6, 10, 0, 4, 3, 18, 2, 18, 17, 6, 16, 19, 12, 18, 4, 4, 16, 12, 13, 11, 0, 0, 12, 7, 10, 2, 7, 12, 4, 18, 13, 18, 16, 17, 14, 12, 1, 12, 4,
14, 8, 18, 4, 12, 10, 1, 18, 7, 2, 9, 3, 11, 12, 2, 9, 13, 12, 18, 15, 1, 9, 5, 11, 6, 12, 9, 16, 14, 18, 0, 15, 4, 17, 5, 1, 13, 0, 10, 0, 6, 16, 15, 3, 16, 20, 18, 4, 18, 16, 3]
list2 = list(set(list1))
list2.sort()
arr = [ for x in list2]
print(arr)
libiao
发表于 2018-1-10 20:49:39
list1 =
max1 = max(list1)
min1 = min(list1)
a=[]
c=[]
for i in list1:
b = list1.count(i)
a.append(b)
for each in list1:
if each not in c:
c.append(each)
d = list(map(lambda x,y:,c,a))
d.sort()
print(d)
libiao
发表于 2018-1-10 20:52:18
list1 =
a=[]
c=[]
for i in list1:
b = list1.count(i)
a.append(b)
for each in list1:
if each not in c:
c.append(each)
d = list(map(lambda x,y:,c,a))
d.sort()
print(d)