-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlex.py
46 lines (44 loc) · 1.55 KB
/
lex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 15 19:20:47 2022
@author: Boris Pérez-Cañedo
"""
import numbers
class Lex:
def __init__(self, *args):
self.l = list(args)
def __lt__(self, other):
if isinstance(other, numbers.Number):
other = Lex(*(other,)*len(self.l))
return self.l < other.l
def __gt__(self, other):
if isinstance(other, numbers.Number):
other = Lex(*(other,)*len(self.l))
return self.l > other.l
def __getitem__(self, i):
return self.l[i]
def __eq__(self, other):
if isinstance(other, numbers.Number):
other = Lex(*(other,)*len(self.l))
return self.l == other.l
def __le__(self, other):
return self < other or self == other
def __ge__(self, other):
return self > other or self == other
def __add__(self, other):
if isinstance(other, numbers.Number):
other = Lex(*(other,)*len(self.l))
return Lex(*[self.l[i]+other.l[i] for i in range(len(self.l))])
def __sub__(self, other):
if isinstance(other, numbers.Number):
other = Lex(*(other,)*len(self.l))
return Lex(*[self.l[i]-other.l[i] for i in range(len(self.l))])
def __len__(self):
return len(self.l)
def __neg__(self):
return Lex(*[-self.l[i] for i in range(len(self.l))])
def __str__(self):
return 'Lex(%s)'%','.join(['%s']*len(self.l)) % tuple(self.l)
def __repr__(self):
return 'Lex(%s)'%','.join(['%s']*len(self.l)) % tuple(self.l)