- :
file_c = list(set(file_a) - set(file_b))
, . , ,
list(set(file_a).difference(file_b))
erhesto. , , ().
Well, after testing, this is what I learned. I installed two different files sub.py and dif.py
Outputs:
swift@pennywise practice $ time python sub.py
[27, 17, 19, 31]
real 0m0.055s
user 0m0.044s
sys 0m0.008s
swift@pennywise practice $ time python dif.py
[17, 19, 27, 31]
real 0m0.056s
user 0m0.032s
sys 0m0.016s
The body of the .py files:
sub.py:
def test():
lsta = [2, 3, 5, 7, 9, 13, 17, 19, 27, 31,]
lstb = [2, 3, 5, 7, 9, 13,]
lstc = list(set(lsta) - set(lstb))
return lstc
if __name__ == '__main__':
print(test())
dif.py
def test():
lsta = [2, 3, 5, 7, 9, 13, 17, 19, 27, 31,]
lstb = [2, 3, 5, 7, 9, 13,]
lstc = list(set(lsta).difference(lstb))
return lstc
if __name__ == '__main__':
print(test())
Edited because I understood the error - forgot to execute the program!
The suboperator is significantly faster on the system than set.difference. So, I would probably stick with '-' compared to set.difference ... it's easier for me to read what happens.
The source for the set () function is set ():
fooobar.com/questions/17273 / ...