Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
5900 มุมมอง

Hi! I'm more or less new in openerp and I need to hide repeated elements of a list ma_ids[ ].

My code is the next:

for rt in r.repairs_ids: m_ids += [rt.id] for rtd in rt.repairs_ids: md_ids += [rtd.id] if (rtd.repair_id.rep_principal==True): ma_ids += [rtd.id]

I need in the last line that rtd.id only writes in ma_ids if rep.principal ==True and I need a condition that if this item already exists that It didn't written it. I try not to display repeated elements.

Sorry for my English, I'm Spanish, If the answer is in Spanish it will be better. :)

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

my_list=[]
#use append(x) to add element in list
my_list.append(1) 
my_list.append(2)
#use count(x) to verify if an element exist in list    
if my_list.count(1) >=1 :
    print 'elemnt 1 exist'
else :
    print 'elemnt 1 not exist'
อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Hi! Thanks you very much! I have got it that way!

Regards.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

However there is more pythonic way to get list with unique elements: Use python set. In this case list(set([1,2,3,2,3,4])) will give you [1,2,3,4].

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 15
8959
5
ธ.ค. 23
18833
7
มี.ค. 20
7708
1
มี.ค. 17
5445
2
ม.ค. 17
3279