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.

1

how to remove the duplicate number of elements in list?

By
Demirel yakito
on 1/20/15, 4:39 AM 1,400 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--
6716
| 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--
3210
| 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.

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

1 follower(s)

Stats

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