DEV Community

I'm Just a Guy with a Computer
I'm Just a Guy with a Computer

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more