-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathgroupTxt_ByClass.py
30 lines (26 loc) · 1.01 KB
/
groupTxt_ByClass.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
def groupItemsBySingleKeyIndex(listItems, keyIndex):
dic_itemGroups={}
for item in listItems:
key=str(item[keyIndex])
dic_itemGroups.setdefault(key, []).append(item)
return dic_itemGroups
##group txt by class
def groupTxtByClass(listtuple_pred_true_text, isByTrueLabel):
dic_tupple_class = {}
if isByTrueLabel == False:
#print("isByPredLabel")
for tuple_pred_true_text in listtuple_pred_true_text:
predLabel = tuple_pred_true_text[0]
trueLabel = tuple_pred_true_text[1]
txt = tuple_pred_true_text[2]
dic_tupple_class.setdefault(predLabel, []).append([predLabel, trueLabel, txt])
else:
#print("isByTrueLabel")
for tuple_pred_true_text in listtuple_pred_true_text:
predLabel = tuple_pred_true_text[0]
trueLabel = tuple_pred_true_text[1]
txt = tuple_pred_true_text[2]
dic_tupple_class.setdefault(trueLabel, []).append([predLabel, trueLabel, txt])
#for key, value in dic_tupple_class.items():
# print(key, len(value))
return dic_tupple_class