DEV Community

Tommi k Vincent
Tommi k Vincent

Posted on

Removing items from a set in Python.

we remove elements from a set by using the discard() method, Again there is no specific index attached to the newly added element.

players = set(['Madueke',' Reece James',' Cole Palmer',' Raheem Sterling',' Levi Colwil',' Thiago Silva',
'Mudryk','cucurella',' Nkunku Christopher'])


players.discard("cucurella")

print(players)
Enter fullscreen mode Exit fullscreen mode

When the above code is executed, it produces the following result.

'Reece James', 'Nkunku Christopher', 'Thiago Silva', 'Mudryk', 'Raheem Sterling', 'Cole Palmer', 'Madueke', 'Levi Colwil'}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)