Example #1
0
 def __init__(self, *args, base):
     if len(args) == 1:
         if isinstance(args[0], Family):
             self.list = args[0].list[:]
             self.base = args[0].base
             return
         if isinstance(args[0], DigitsList):
             self.list = [args[0]]
             self.base = args[0].base
             return
         if it.is_iterable(args[0]):
             args = list(args[0])
         else:
             args = [args[0]]
     self.base = base
     self.list = []
     for i in args:
         if isinstance(i, int):
             i = str_base(i, self.base)
         if isinstance(i, str):
             try:
                 int(i, base)
             except:
                 raise TypeError("'%s' isn't a base %s number" % (i, base))
             self.list.append(i)
         elif it.is_iterable(i):
             if it.is_emply(i): pass
             if len(i) == 1: self.list.append(Digits(i[0], base=self.base))
             else: self.list.append(DigitsList(i, base=self.base))
Example #2
0
 def __init__(self, *args, base):
     if len(args) == 1:
         if isinstance(args[0], DigitsList):
             self.list = args[0].list[:]
             self.base = args[0].base
             return
         if isinstance(args[0], str):
             try:
                 int(args[0], base)
             except:
                 raise TypeError("'%s' isn't a base %s number" %
                                 (args[0], base))
             self.list = [args[0]]
             self.base = base
             return
         if it.is_iterable(args[0]):
             self.list = list(args[0])
         else:
             self.list = [args[0]]
     else:
         self.list = list(args)
     self.base = base
     self.list = list(map(lambda x: str_base(x, self.base), self.list))
     self.list.sort(key=lambda x: int(x, self.base))
     self.list = list(it.unique(self.list))
Example #3
0
 def __radd__(self, other):
     if not it.is_iterable(other):
         other = [other]
     t = iter2(self.iterable)
     t.start = other
     t.end = self.end
     return t
Example #4
0
 def __add__(self, other):
     if not it.is_iterable(other):
         other = [other]
     t = iter2(self.iterable)
     t.start = self.start
     t.add(self.end)
     t.add(other)
     return t
Example #5
0
 def __init__(self, f, context=default_context):
     """f:list"""
     if isinstance(f, Expr):
         self.body = f.body
         self.context = f.context
     else:
         self.body = list(
             f) if it.is_iterable(f) and not (isinstance(f, str)) else [f]
         self.context = context
Example #6
0
 def __mul__(self, other):
     if isinstance(other, int):
         other = str_base(other, base=self.base)
     if isinstance(other, str):
         other = DigitsList([other], base=self.base)
     if it.is_iterable(other):
         if it.is_emply(other):
             return self
         other = DigitsList(other, base=self.base)
     if self.base != other.base: raise Exception("base must be equal")
     return DigitsList(list(
         map(lambda x: x[0] + x[1],
             itertools.product(self.list, other.list))),
                       base=self.base)
Example #7
0
 def __rmul__(self, other):
     if it.is_iterable(other):
         if it.is_emply(other):
             return self
     return DigitsList(other, base=self.base) * self