70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
from typing import List
|
||
|
||
|
||
class CoreList(List):
|
||
"""
|
||
Class for handling cases related to lists:
|
||
|
||
Args:
|
||
List (list): list to analysis
|
||
"""
|
||
|
||
def onlyTrue(self) -> bool:
|
||
for el in self:
|
||
if el is True:
|
||
return True
|
||
return False
|
||
|
||
def onlyUniqueElementAppend(self, el):
|
||
if el is None:
|
||
return
|
||
if self.is_element_in_array(el) is False:
|
||
self.append(el)
|
||
pass
|
||
|
||
def is_element_in_array(self, element):
|
||
return element in self
|
||
|
||
def equal(self, array: list) -> bool:
|
||
"""Сhecking that the analyzed list is equal to the reference list
|
||
|
||
Args:
|
||
array (list): reference list
|
||
|
||
Returns:
|
||
bool:
|
||
"""
|
||
if len(self) != len(array):
|
||
return False
|
||
return self.sort() == array.sort()
|
||
|
||
def isConstrainsString(self) -> bool:
|
||
for el in self:
|
||
if isinstance(el, str):
|
||
return True
|
||
return False
|
||
|
||
def indexedPriorities(self, lowerPriority, highPriority) -> bool:
|
||
try:
|
||
lowerIndex = self.index(lowerPriority)
|
||
highPriorityIndex = self.index(highPriority)
|
||
return lowerIndex < highPriorityIndex
|
||
except:
|
||
return False
|
||
|
||
def getAllString(self) -> list[str]:
|
||
return list(filter(lambda x: isinstance(x, str), self))
|
||
|
||
def onlyUnique(self) -> list:
|
||
result = []
|
||
[result.append(x) for x in self if x not in self]
|
||
return result
|
||
|
||
def spreadArray(self) -> "CoreList":
|
||
unpacked_array = CoreList([])
|
||
for el in self:
|
||
if isinstance(el, list):
|
||
unpacked_array.extend(el)
|
||
else:
|
||
unpacked_array.append(el)
|
||
return unpacked_array
|