- class Field(dict):
- @classmethod
- def __check_string(cls, s):
- if s.isalnum():
- k = 0
- for i in s:
- if i.isalpha():
- k += 1
- elif i.isdigit():
- continue
- if k > 1:
- raise ValueError
- else:
- raise ValueError
- @classmethod
- def __check_key(cls, key):
- if isinstance(key, (tuple, str)):
- l = 0
- if isinstance(key, tuple):
- for i in key:
- if not isinstance(i, (str, int)):
- raise ValueError
- else:
- if isinstance(i, int):
- if not i >= 0:
- raise ValueError
- elif isinstance(i, str):
- if i.isalpha():
- l += 1
- if l > 1:
- raise ValueError
- cls.__check_string(i)
- elif isinstance(key, str):
- cls.__check_string(key)
- else:
- raise TypeError
- def __setitem__(self, key, value):
- self.__check_key(key)
- key = ''.join(str(x) for x in key)
- if key.lower() not in self.__dict__.keys():
- return self.__dict__.setdefault(key.lower(), value)
- else:
- self.__dict__[key.lower()] = value
- def __getitem__(self, item):
- self.__check_key(item)
- item = ''.join(str(x) for x in item)
- if item.lower() in self.__dict__.keys():
- return self.__dict__.get(item.lower())
- elif item[::-1].lower() in self.__dict__.keys():
- return self.__dict__.get(item[::-1].lower())
- else:
- return None
- def __delitem__(self, key):
- self.__check_key(key)
- key = ''.join(str(x) for x in key)
- if key.lower() in self.__dict__.keys():
- del self.__dict__[key.lower()]
- elif key.lower()[::-1] in self.__dict__.keys():
- del self.__dict__[key.lower()[::-1]]
- def __iter__(self):
- self.fiksator = -1
- return self
- def __contains__(self, item):
- item = ''.join(str(x) for x in item)
- return item.lower() in self.__dict__.keys() or item[::-1].lower() in self.__dict__.keys()
- def __next__(self):
- self.fiksator += 1
- if self.fiksator < len(self.__dict__) - 1:
- a = list(self.__dict__.keys())[:list(self.__dict__.keys()).index('fiksator')]
- return self.__dict__[a[self.fiksator]]
- else:
- raise StopIteration
[text] 18
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- 18
- Paste Code
- 26 Nov-2022
- 2.7 Kb
You can Share it:
Latest Code Pastes