-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNote_group_by_samefeature.py
53 lines (48 loc) · 1.01 KB
/
Note_group_by_samefeature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# encoding: utf-8
# product.py
# product
# Created by txooo on 2018/11/19
# Copyright © 2018 txooo. All rights reserved.
a = [{'key':1, 'value':2},
{'key':2, 'value':3},
{'key':1, 'value':4},
{'key':4, 'value':5},
{'key':2, 'value':6},
{'key':None, 'value':7},
{'key': 1, 'value': 2},
{'key': 2, 'value': 3},
{'key': 1, 'value': 4},
{'key': 4, 'value': 5},
{'key': 5, 'value': 6},
{'key': 8, 'value': 7}
]
c = list()
for item in a:
find:bool = False
for sub_list in c:
sub_item = sub_list[0]
if sub_item['key'] == item['key']:
sub_list.append(item)
find = True
break
if not find:
sub_list_new = list()
sub_list_new.append(item)
c.append(sub_list_new)
print(c)
# from itertools import groupby
#
# a = [1, 2, 3, 2, 1, 5, 6, 5, 5, 5]
# b = set(a)
# c = list()
# for each_b in b:
# count = 0
# for each_a in a:
# if each_b == each_a:
# count += 1
# c.append(each_a)
# print(each_b, ": ", count)
# d = [list(v) for _, v in groupby(c)]
# print(c)
# print(d)