- pop() in a dictionary slightly same as popitem() function, both are able to pop(delete) the item from the dictionary.
- popitem() function remove the top most item of the dictionary.
- while pop() function remove the specified item from the dictionary.
Syntax-
dict.pop(key)
Example-
dictionary is d={1:"one",2:"two",3:"three"}
d.pop(1)
will give {2:"two",3:"three"}
program-
d={1:"one",2:"two",3:"Three",4:"Four"}
print(d)
d.pop(1)
print(d)
d.pop(2)
print(d)
d.pop(3)
print(d)
d.pop(4)
print(d)
{1: 'one', 2: 'two', 3: 'Three', 4: 'Four'}
{2: 'two', 3: 'Three', 4: 'Four'}
{3: 'Three', 4: 'Four'}
{4: 'Four'}
{}
d={1:"one",2:"two",3:"Three",4:"Four"}
print(d)
d.pop()
print(d)
d.pop()
TypeError: pop expected at least 1 arguments, got 0