我有一张单子
[<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 46L, 'PatientProfile_ID': 2L}>,
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 46L, 'PatientProfile_ID': 2L}>,
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 46L, 'PatientProfile_ID': 2L}>,
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 46L, 'PatientProfile_ID': 2L}>,
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>]
我想要这个的独特价值 预期结果是
[
<Storage {'CaseID': 45L, 'PatientProfile_ID': 3L}>,
<Storage {'CaseID': 46L, 'PatientProfile_ID': 2L}>
]
正在从数据库中提取此数据。请不要建议我在数据库中使用DISTINCT关键字。它已被另一列排序。使用distinct将删除排序结果。你知道吗
可以用python实现。或者我必须写一个for循环来做同样的事情吗?你知道吗
霉菌代码
entries=db.query("SELECT cases.ID as CaseID,PatientProfile_ID FROM \
`callog` ,consultation,cases WHERE callog.Consultation_ID=consultation.ID and consultation.Case_ID = cases.ID and \
Doctor_ID="+str(Id)+" ORDER BY callog.CallDate DESC")
rows=entries.list()
return rows
试试这个:
上面,将您的列表转换为一个集合(删除重复项),然后再返回到一个列表中。你知道吗
有关更多信息,请参阅this。看,如果有帮助的话。你知道吗
这应该处理得很好。你知道吗
使用
seen_add
可以加速操作。你知道吗另见this SO question。你知道吗
由于问题似乎是您的项目属于
Storage
类型,请尝试以下操作:在经历了所有的尝试和错误之后,我又回到了For循环
片段礼貌:@Richard
相关问题 更多 >
编程相关推荐