I'm fairly new at Python and i cannot wrap my head around the results im getting Using the code below:
def func(a,b=set()):
res=list()
for i in a:
if i not in b:
res.append(i)
b|={i}
return res
print(func([1,1,2,2,3,4]))
print(func([1,1,2,2,3,4]))
I was getting output:
[1,2,3,4]
[]
I put "print(b)" above "res=list()" and got output:
set()
[1,2,3,4]
{1,2,3,4}
[]
What is going on? Shouldn't "b" be set to "set()" when i call the function? Im using Python 3.6