Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Hide repeated elements of a list? [solved]

By
Souldor
on 8/21/13, 5:40 AM 1,684 views

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. :)

1

Borni DHIFI

--Borni DHIFI--
5102
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 

http://www.linkedin.com/in/borni

Skype : dhifi.borni

Borni DHIFI
On 8/21/13, 6:08 AM

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'
0
Souldor
On 8/28/13, 2:22 PM

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

Regards.

0
nazarii
On 8/28/13, 3:49 PM

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].

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 8/21/13, 5:40 AM
Seen: 1684 times
Last updated: 3/16/15, 8:10 AM