Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __contains__(self, other):
"""Check if other is a permutation in the set."""
return isinstance(other, Perm) and len(other) == self.length
def __init__(self, *args):
try:
if len(args) == 0:
self._zb_perm = _ZBPerm()
elif len(args) == 1:
arg = args[0]
if isinstance(arg, _ZBPerm):
self._zb_perm = arg
elif isinstance(arg, Perm):
self._zb_perm = arg._zb_perm
elif isinstance(arg, numbers.Integral):
self._zb_perm = _ZBPerm.to_standard(str(arg))
else:
self._zb_perm = _ZBPerm.to_standard(arg)
else:
self._zb_perm = _ZBPerm.to_standard(args)
except Exception:
format_string = "Don't know how to get a perm from args: {}"
message = format_string.format(args)
raise ValueError(message)
def __contains__(self, perm):
return isinstance(perm, Perm) # Why would you even ask?
def random(self):
"""Return a random perm of the length."""
all_elements = self.domain
random.shuffle(all_elements)
return Perm(all_elements)
def __contains__(self, item):
return isinstance(item, Perm) and item in self._set
def __getitem__(self, key):
return Perm.unrank(key)
def __repr__(self):
if self._zb_perm == _ZBPerm((0,)):
return "(1)"
else:
return str(tuple(self))
def __getitem__(self, key):
return Perm.unrank(key, self.length)
def random(cls, length):
"""Return a random perm of the specified length."""
return cls(_ZBPerm.random(length))
def __init__(self, *args):
try:
if len(args) == 0:
self._zb_perm = _ZBPerm()
elif len(args) == 1:
arg = args[0]
if isinstance(arg, _ZBPerm):
self._zb_perm = arg
elif isinstance(arg, Perm):
self._zb_perm = arg._zb_perm
elif isinstance(arg, numbers.Integral):
self._zb_perm = _ZBPerm.to_standard(str(arg))
else:
self._zb_perm = _ZBPerm.to_standard(arg)
else:
self._zb_perm = _ZBPerm.to_standard(args)
except Exception:
format_string = "Don't know how to get a perm from args: {}"
message = format_string.format(args)
raise ValueError(message)