MCPcopy
hub / github.com/TheAlgorithms/Python / extend

Method extend

data_structures/queues/double_ended_queue.py:183–210  ·  view source on GitHub ↗

Appends every value of iterable to the end of the deque. Time complexity: O(n) >>> our_deque_1 = Deque([1, 2, 3]) >>> our_deque_1.extend([4, 5]) >>> our_deque_1 [1, 2, 3, 4, 5] >>> our_deque_2 = Deque('ab') >>> our_deque_2.extend('cd')

(self, iterable: Iterable[Any])

Source from the content-addressed store, hash-verified

181 assert not self.is_empty(), "Error on appending value."
182
183 def extend(self, iterable: Iterable[Any]) -> None:
184 """
185 Appends every value of iterable to the end of the deque.
186 Time complexity: O(n)
187 >>> our_deque_1 = Deque([1, 2, 3])
188 >>> our_deque_1.extend([4, 5])
189 >>> our_deque_1
190 [1, 2, 3, 4, 5]
191 >>> our_deque_2 = Deque('ab')
192 >>> our_deque_2.extend('cd')
193 >>> our_deque_2
194 ['a', 'b', 'c', 'd']
195 >>> from collections import deque
196 >>> deque_collections_1 = deque([1, 2, 3])
197 >>> deque_collections_1.extend([4, 5])
198 >>> deque_collections_1
199 deque([1, 2, 3, 4, 5])
200 >>> deque_collections_2 = deque('ab')
201 >>> deque_collections_2.extend('cd')
202 >>> deque_collections_2
203 deque(['a', 'b', 'c', 'd'])
204 >>> list(our_deque_1) == list(deque_collections_1)
205 True
206 >>> list(our_deque_2) == list(deque_collections_2)
207 True
208 """
209 for val in iterable:
210 self.append(val)
211
212 def extendleft(self, iterable: Iterable[Any]) -> None:
213 """

Callers 15

_elementsMethod · 0.45
round_robinMethod · 0.45
convoluteMethod · 0.45
_expandMethod · 0.45
predictMethod · 0.45
_msd_radix_sortFunction · 0.45
strand_sortFunction · 0.45
mergeFunction · 0.45
__add__Method · 0.45
clone_graphFunction · 0.45
_count_cross_inversionsFunction · 0.45

Calls 1

appendMethod · 0.95

Tested by

no test coverage detected