Odoo Help

1

how to remove the duplicate number of elements in list?

By
Demirel yakito
on 1/20/15, 4:39 AM 1,915 views

iam hving list with repeated elements. so in this case how to delete the duplicate elements in the list using python?

1

Yenthe

--Yenthe--
7155
| 7 7 8
Turnhout, Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 1/20/15, 4:40 AM

For example:

def formatList(seq):
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if not (x in seen or seen_add(x))]

There are loads of topics about this on stackoverflow and Google. This example is taken from http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order and also keeps the order of your list!

 

A second option could be to create a second list, which only contains the clean values. In case you would like to keep both lists.

for i in mylist:
     if i not in newlist:
          newlist.append(i)

list = set(list) is this correct?

Demirel yakito
on 1/20/15, 4:49 AM
1

Ivan

--Ivan--
3255
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/20/15, 6:16 AM

I usually used list_wo_no_duplicate = list(set(list_with_ducplicates))  to remove duplicates.  Although I think there is no harm for not setting the variable to list again as set in most cases.

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/20/15, 4:39 AM
Seen: 1915 times
Last updated: 3/16/15, 8:10 AM