How can I handle the different operations between sets in python Union, Intersection, Difference, Symmetric Difference, Complement, Cartesian Product
A = {1, 2, 3, 4}
B = {1, 3, 6, 7}
A ∪ B
A ∩ B
A \ B
...
...
A × B
How can I handle the different operations between sets in python Union, Intersection, Difference, Symmetric Difference, Complement, Cartesian Product
A = {1, 2, 3, 4}
B = {1, 3, 6, 7}
A ∪ B
A ∩ B
A \ B
...
...
A × B
How can I overload operators (+, -, *, /, ... , //)
on an object in python.
Example:
a = Vector(3, 5)
b = Vector(2, 7)
print(a + b) # Output: <Vector (5.000000, 12.000000)>
print(b - a) # Output: <Vector (-1.000000, 2.000000)>
print(b * 1.3) # Output: <Vector (2.600000, 9.100000)>
print(a // 17) # Output: <Vector (0.000000, 0.000000)>
print(a / 17) # Output: <Vector (0.176471, 0.294118)>
where Vector
is the following class:
class Vector(object):
def __init__(self, x, y):
self.x = x
self.y = y
I need to implement a decorator with classes or functions that receive parameters, like the following example
@MyDec(flag='foo de fa fa')
def bar(a,b,c):
print('En bar(...) : ',a,b,c)