Python:Remove duplicates without sorting?

Python:Remove duplicates without sorting?i want lines keep the order and not be sorted,anywaone have a  good python script?
thank you
john lambertAsked:
Who is Participating?
 
Dan CraciunConnect With a Mentor IT ConsultantCommented:
def remove_dups(seq):  
    result = []
    for val in seq:
        if val not in result:
            result.append(val)
    return result

Open in new window


Not fast for huge lists, but easy to understand.

HTH,
Dan
1
 
Dan CraciunIT ConsultantCommented:
A faster solution, taken from here:

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

Open in new window

1
 
john lambertAuthor Commented:
I want the most eficient solution, ok thank you
0
 
aikimarkCommented:
the more_itertools library has a unique_everseen() method
https://pythonhosted.org/more-itertools/api.html
0
 
john lambertAuthor Commented:
thank you........
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.