18Breakageratecalculation non-broken roofing 18Breakageratecalculation broken roofing 18Breakageratecalculation non-broken roofing 18Breakageratecalculation non-broken roofing 18Breakageratecalculation non-broken roofing 18Breakageratecalculation non-broken roofing 18Breakageratecalculation courtyard 18Breakageratecalculation non-broken roofing把txt文件的标签按顺序排序并对应0:non-broken roofing,1:broken roofing,2:courtyard代码
时间: 2024-03-21 17:42:32 浏览: 57
fr-static:Franki Roofing的投资组合
假设txt文件名为labels.txt,可以使用以下代码将文件中的标签按顺序排序并对应为0:non-broken roofing, 1:broken roofing, 2:courtyard:
```python
with open('labels.txt', 'r') as f:
labels = f.read().split()
sorted_labels = sorted(labels)
label_dict = {'non-broken roofing': 0, 'broken roofing': 1, 'courtyard': 2}
label_list = [label_dict[label] for label in sorted_labels]
print(label_list)
```
该代码会将文件中的标签读取到列表labels中,排序后将其对应为0:non-broken roofing, 1:broken roofing, 2:courtyard,并将其存储在列表label_list中。最后打印label_list。
阅读全文