How does "non x" work in a python set method?

im new for Python3.3, and I wanted to remove duplicate items from the list, I found this short code on the net, but I don’t know what is the logic of this code ?, especially the part “not seen_add (x)” !.

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

can someone clarify this for me ?!

+1
source share
1 answer

add None. None , not seen_add(x) True. and , seen_add(x) , x , . seen_add(x) , x , -, not seen_add(x) .

,

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

and seen_add, :

def f7(seq):
    seen=set()
    result = []
    for x in seq:
        if x not in seen:
            seen.add(x)
            result.append(x)
    return result
+2

Source: https://habr.com/ru/post/1663479/


All Articles