19 Python對列表元素進行去重操作

2021-10-01 21:36:50 字數 3077 閱讀 4886

問題描述: 存在一條跟蹤軌跡資訊,目的是尋找最大置信度的類別資訊,進行類別跳變和區域變化統計;

track_data=[[0.9,3,'i'],[0.7,3,'i'],[0.1,3,'i'],[0.9,2,'o'],[0.98,2,'o'],[0.7,3,'i'],[0.1,3,'i'],[0.9,2,'o']] 含義為 分數、類別資訊 區域位置

分數:為類別資訊的置信度

類別資訊:為目標a=3 目標b=2 

區域資訊i 為內區域 o為外區域

結果為:[[0.9, 3, 'i'], [0.9, 2, 'o'], [0.7, 3, 'i'], [0.9, 2, 'o']]

import os

track_data=[[951, 2, 1100, 247, 1229, 336, 1, 0, 0, true, false, 0.5361185669898987, 3, 0, 'o'], [952, 2, 1055, 250, 1184, 339, 0.45901639344262296, 1, 1, true, false, 0.5182264447212219, 3, 1, 'o'], [953, 2, 1044, 148, 1202, 313, 0.27620309951060357, 0, 0, true, false, 0.7706855535507202, 3, 0, 'o'], [954, 2, 1020, 99, 1181, 277, 0.4769396842531372, 0, 0, true, false, 0.5893790125846863, 3, 0, 'o'], [955, 2, 1000, 65, 1161, 243, 0.5485788392953637, 1, 1, true, false, 0.5893790125846863, 3, 1, 'i'], [956, 2, 979, 25, 1142, 268, 0.5879370100718755, 0, 0, true, false, 0.7298511266708374, 3, 0, 'i'], [957, 2, 984, 23, 1143, 259, 0.9205946067080003, 0, 0, true, false, 0.7313498854637146, 3, 0, 'i'], [958, 2, 985, 20, 1144, 256, 0.9628602814249098, 1, 1, true, false, 0.7313498854637146, 3, 1, 'i'], [959, 2, 978, 53, 1151, 262, 0.779562361124529, 0, 0, true, false, 0.7412099838256836, 3, 0, 'i'], [960, 2, 976, 89, 1158, 263, 0.789766729997889, 0, 0, true, false, 0.6838870048522949, 3, 0, 'o'], [961, 2, 980, 100, 1162, 274, 0.8453470077501312, 1, 1, true, false, 0.6838870048522949, 3, 1, 'o'], [962, 2, 985, 105, 1167, 279, 0.8949824970828472, 2, 2, true, false, 0.6838870048522949, 3, 1, 'o'], [963, 2, 985, 105, 1167, 279, 1.0, 3, 3, true, false, 0.6838870048522949, 3, 1, 'o'], [964, 2, 980, 105, 1162, 279, 0.946524064171123, 4, 4, true, false, 0.6838870048522949, 3, 1, 'o'], [965, 2, 980, 105, 1162, 279, 1.0, 5, 5, true, false, 0.6838870048522949, 3, 1, 'o'], [966, 2, 975, 105, 1157, 279, 0.946524064171123, 6, 6, true, true, 0.6838870048522949, 3, 1, 'o']]

k=len(track_data)

m=0for i in range(0,k):

for j in range(i+1,k):

j=j-m

if j>=k:

break

if track_data[i][-1]!=track_data[j][-1]:

m=0break

elif track_data[i][-4]>=track_data[j][-4]:

track_data.pop(j)

k=k-1

m=m+1

else:

track_data[i]=track_data[j].copy()

track_data.pop(j)

k=k-1

m=m+1

print (track_data)

[[953, 2, 1044, 148, 1202, 313, 0.27620309951060357, 0, 0, true, false, 0.7706855535507202, 3, 0, 'o'], [959, 2, 978, 53, 1151, 262, 0.779562361124529, 0, 0, true, false, 0.7412099838256836, 3, 0, 'i'], [960, 2, 976, 89, 1158, 263, 0.789766729997889, 0, 0, true, false, 0.6838870048522949, 3, 0, 'o']]
data=

for track_id,track_item in enumerate(track_data):

if track_id==0:

continue

if data[-1][-1]!=track_item[-1] or data[-1][-3]!=track_item[-3]:

if data[-1][-4]>track_item[-4] and data[-1][-1]==track_item[-1]:

continue

elif data[-1][-4]data[-1]=track_item

print (data,"data-----------")

19 python 列表的常見操作

定義變數a,預設有3個元素 a xiaowang xiaozhang xiaohua print 新增之前,列表a的資料 for tempname in a print tempname 提示 並新增元素 temp input 請輸入要新增的學生姓名 print 新增之後,列表a的資料 for te...

學習日記19 python列表排序與複製

列表的排序 sorted ls,reverse true sorted函式 將a從小到大排序,不影響a本身結構,返回值是乙個列表。ls.sort reverse true sort函式 將a從小到大排序,影響a本身結構,返回值是none 如果元素是字母,則按照每個字母的ascii碼從小到大排序。新增...

Python學習19 python類的繼承

父類 子類 繼承如何表示?class 子類名 父類名 pass子類可以實現自己獨有的方法 重寫 super 超繼承 使用父類當中的方法 例項1 class man name man def init self self.name print man.name print man csdn name ...