How to use _elements method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

multiset.py

Source:multiset.py Github

copy

Full Screen

...222 return not self._issubset(other, False) and len(self) != len(other)223 def get(self, element: T, default: t.Optional[V] = None) -> t.Union[int, V, None]:224 return self._elements.get(element, default)225 @classmethod226 def from_elements(cls, elements: t.Iterable[T], multiplicity: int) -> BaseMultiset[T]:227 return cls(dict.fromkeys(elements, multiplicity))228 def __copy__(self) -> BaseMultiset[T]:229 return self.__class__(self)230 def items(self) -> t.Iterable[t.Tuple[T, int]]:231 return self._elements.items()232 def distinct_elements(self) -> t.KeysView[T]:233 return self._elements.keys()234 def multiplicities(self) -> t.Iterable[int]:235 return self._elements.values()236 def elements(self) -> t.Mapping[T, int]:237 return self._elements238 values: t.Callable[[], t.ValuesView[T]] = multiplicities239 @classmethod240 def _as_multiset(cls, other: t.Iterable[T]) -> BaseMultiset[T]:241 if isinstance(other, BaseMultiset):242 return other243 return cls(other)244 @classmethod245 def _as_mapping(cls, iterable: t.Iterable[T]) -> t.Mapping[T, int]:246 if isinstance(iterable, BaseMultiset):247 return iterable._elements248 if isinstance(iterable, t.Mapping):249 return iterable250 mapping = defaultdict(int)251 for element in iterable:252 mapping[element] += 1253 return mapping254 def __getstate__(self):255 return self._elements256 def __setstate__(self, state):257 self._elements = state258class BaseOrderedMultiset(BaseMultiset[T]):259 __slots__ = ()260 def __init__(self, iterable: t.Optional[t.Iterable[T]] = None) -> None:261 if isinstance(iterable, __class__):262 self._elements = copy.copy(iterable._elements)263 return264 self._elements: OrderedDefaultDict[T, int] = OrderedDefaultDict(int)265 if iterable is not None:266 if isinstance(iterable, t.Mapping):267 for element, multiplicity in iterable.items():268 if multiplicity > 0:269 self._elements[element] = multiplicity270 else:271 for element in iterable:272 self._elements[element] += 1273class BaseIndexedOrderedMultiset(BaseOrderedMultiset[T]):274 __slots__ = ()275 def __init__(self, iterable: t.Optional[t.Iterable[T]] = None) -> None:276 if isinstance(iterable, __class__):277 self._elements = copy.copy(iterable._elements)278 return279 self._elements: IndexedOrderedDefaultDict[T, int] = IndexedOrderedDefaultDict(int)280 if iterable is not None:281 if isinstance(iterable, t.Mapping):282 for element, multiplicity in iterable.items():283 if multiplicity > 0:284 self._elements[element] = multiplicity285 else:286 for element in iterable:287 self._elements[element] += 1288 def get_value_at_index(self, index: int) -> T:289 return self._elements.get_key_by_index(index)290 def get_multiplicity_at_index(self, index: int) -> int:291 return self._elements.get_value_by_index(index)292 def get_index_of_item(self, item: T) -> int:293 return self._elements.get_index_of_key(item)294class Multiset(BaseMultiset[T]):295 __slots__ = ()296 def __setitem__(self, element: T, multiplicity: int) -> None:297 _elements = self._elements298 if element in _elements:299 if multiplicity > 0:300 _elements[element] = multiplicity301 else:302 del _elements[element]303 elif multiplicity > 0:304 _elements[element] = multiplicity305 def __delitem__(self, element: T) -> None:306 if element in self._elements:307 del self._elements[element]308 else:309 raise KeyError("Could not delete {!r} from the multiset, because it is not in it.".format(element))310 def update(self, *others: t.Iterable[T]) -> Multiset[T]:311 for other in map(self._as_mapping, others):312 for element, multiplicity in other.items():313 self._elements[element] += multiplicity314 return self315 def union_update(self, *others: t.Iterable[T]) -> Multiset[T]:316 _elements = self._elements317 for other in map(self._as_mapping, others):318 for element, multiplicity in other.items():319 old_multiplicity = _elements.get(element, 0)320 if multiplicity > old_multiplicity:321 _elements[element] = multiplicity322 return self323 def __ior__(self, other: t.Iterable[T]) -> Multiset[T]:324 return self.union_update(other)325 def intersection_update(self, *others: t.Iterable[T]) -> Multiset[T]:326 for other in map(self._as_mapping, others):327 for element, current_count in self.items():328 multiplicity = other.get(element, 0)329 if multiplicity < current_count:330 self[element] = multiplicity331 return self332 def __iand__(self, other: t.Iterable[T]) -> Multiset[T]:333 return self.intersection_update(other)334 def difference_update(self, *others: t.Iterable[T]) -> Multiset[T]:335 for other in map(self._as_multiset, others):336 for element, multiplicity in other.items():337 self.discard(element, multiplicity)338 return self339 def __isub__(self, other: t.Iterable[T]) -> Multiset[T]:340 return self.difference_update(other)341 def symmetric_difference_update(self, other: t.Iterable[T]) -> Multiset[T]:342 other = self._as_multiset(other)343 elements = self.distinct_elements() | other.distinct_elements()344 for element in elements:345 multiplicity = self[element]346 other_count = other[element]347 self[element] = (multiplicity - other_count if multiplicity > other_count else other_count - multiplicity)348 return self349 def __ixor__(self, other: t.Iterable[T]) -> Multiset[T]:350 return self.symmetric_difference_update(other)351 def times_update(self, factor: int) -> Multiset[T]:352 if factor < 0:353 raise ValueError("The factor must not be negative.")354 elif factor == 0:355 self.clear()356 else:357 _elements = self._elements...

Full Screen

Full Screen

counters.py

Source:counters.py Github

copy

Full Screen

...89 return self.times(-1)90 def get(self, element: T, default: t.Optional[V] = None) -> t.Union[int, V, None]:91 return self._elements.get(element, default)92 @classmethod93 def from_elements(cls, elements: t.Iterable[T], multiplicity: int) -> BaseCounter[T]:94 return cls(dict.fromkeys(elements, multiplicity))95 def copy(self) -> BaseCounter[T]:96 return self.__class__(self)97 __copy__ = copy98 def items(self) -> t.Iterable[t.Tuple[T, int]]:99 return self._elements.items()100 def distinct_elements(self) -> t.KeysView[T]:101 return self._elements.keys()102 def multiplicities(self) -> t.ValuesView[int]:103 return self._elements.values()104 def positive(self) -> t.Iterator[t.Tuple[T, int]]:105 return (106 (element, multiplicity)107 for element, multiplicity in108 self._elements.items()109 if multiplicity > 0110 )111 def negative(self) -> t.Iterator[t.Tuple[T, int]]:112 return (113 (element, multiplicity)114 for element, multiplicity in...

Full Screen

Full Screen

堆实现.py

Source:堆实现.py Github

copy

Full Screen

1class Array(object):2 """3 Achieve an Array by Python list4 """5 def __init__(self, size = 32):6 self._size = size7 self._items = [None] * size8 def __getitem__(self, index):9 """10 Get items11 :param index: get a value by index12 :return: value13 """14 return self._items[index]15 def __setitem__(self, index, value):16 """17 set item18 :param index: giving a index you want to teset19 :param value: the value you want to set20 :return:21 """22 self._items[index] = value23 def __len__(self):24 """25 :return: the length of array26 """27 return self._size28 def clear(self, value=None):29 """30 clear the Array31 :param value: set all value to None32 :return: None33 """34 for i in range(self._size):35 self._items[i] = value36 def __iter__(self):37 for item in self._items:38 yield item39class MinHeap(object):40 """41 Achieve a minimum heap by Array42 """43 def __init__(self, maxsize = None):44 self.maxsize = maxsize45 self._elements = Array(maxsize)46 self._count = 047 def __len__(self):48 return self._count49 def add(self, value):50 """51 Add an element to heap while keeping the attribute of heap unchanged.52 :param value: the value added to the heap53 :return: None54 """55 if self._count >= self.maxsize:56 raise Exception("The heap is full!")57 self._elements[self._count] = value58 self._count += 159 self._siftup(self._count-1)60 def _siftup(self, index):61 """62 To keep the the attribute of heap unchanged while adding a new value.63 :param index: the index of value you want to swap64 :return: None65 """66 if index > 0:67 parent = int((index - 1) / 2)68 if self._elements[parent] > self._elements[index]:69 self._elements[parent], self._elements[index] = self._elements[index], self._elements[parent]70 self._siftup(parent)71 def extract(self):72 """73 pop and return the value of root74 :return: the value of root75 """76 if self._count <= 0:77 raise Exception('The heap is empty!')78 value = self._elements[0]79 self._count -= 180 self._elements[0] = self._elements[self._count]81 self._siftdown(0)82 return value83 def _siftdown(self, index):84 """85 to keep the attribute of heap unchanged while pop out the root node.86 :param index: the index of value you want to swap87 :return: None88 """89 if index < self._count:90 left = 2 * index + 191 right = 2 * index + 292 if left < self._count and right < self._count \93 and self._elements[left] <= self._elements[right] \94 and self._elements[left] <= self._elements[index]:95 self._elements[left], self._elements[index] = self._elements[index], self._elements[left]96 self._siftdown(left)97 elif left < self._count and right < self._count \98 and self._elements[left] >= self._elements[right] \99 and self._elements[right] <= self._elements[index]:100 self._elements[right], self._elements[index] = self._elements[index], self._elements[right]101 self._siftdown(left)102 if left < self._count and right > self._count \103 and self._elements[left] <= self._elements[index]:104 self._elements[left], self._elements[index] = self._elements[index], self._elements[left]105 self._siftdown(left)106if __name__ == '__main__':107 import random108 n = 5109 h = MinHeap(n)110 for i in range(n):111 h.add(i)112 for i in range(n):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lettuce_webdriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful