8 examples of 'python dictionary pop' in Python

Every line of 'python dictionary pop' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
144def popitem(self):
145 try:
146 k, v = self.iteritems().next()
147 except StopIteration:
148 raise KeyError, 'container is empty'
149 del self[k]
150 return (k, v)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

162def popitem(self):
163 """ D.popitem() -> (k, v), remove and return some (key, value) pair
164 as a 2-tuple; but raise KeyError if D is empty """
165 while True:
166 key, sleek_ref = self.data.popitem()
167 try:
168 return key, sleek_ref()
169 except SleekRefDied:
170 pass
492def test_pop(self):
493
494 twd_copy = self.twd.copy()
495 v = twd_copy.pop(self.test_keys[0])
496 self.assertEqual(self.test_vals[0], v)
497 self.assert_(not twd_copy.has_key(self.test_keys[0]))
498 self.assert_(not twd_copy.has_value(v))
160def pop(self, key, *args):
161 if len(args) > 1:
162 raise TypeError, "pop expected at most 2 arguments, got "\
163 + repr(1 + len(args))
164 for i in range(len(self._items)):
165 if self._items[i][0] == key:
166 v = self._items[i][1]
167 del self._items[i]
168 return v
169 if args:
170 return args[0]
171 else:
172 raise KeyError(key)
122def pop(self, key, *default):
123 present = key in self
124 value = dict.pop(self, key, *default)
125 if present:
126 self._list.remove(key)
127 return value
210def pop(self, key, default=missing):
211 try:
212 value = dict.pop(self, key)
213 self._keys.remove(key)
214 return value
215 except KeyError as e:
216 if default == missing:
217 raise e
218 else:
219 return default
370def popitem(self):
371 while 1:
372 key, value = self.data.popitem()
373 o = key()
374 if o is not None:
375 return (o, value)
376
377 return
190def pop(self, key, default=missing):
191 if default is missing:
192 return dict.pop(self, key)
193 self._keys.remove(key)
194 return dict.pop(self, key, default)

Related snippets