Is there a python set deleting method that returns a value if the value you want to delete is not in the set? -


is there deleting method deleting element of set takes parameter return if there no element delete matches parameter gave delete?

so set.discard(a,b) parameter want delete , b parameter gets returned if not found.

something this?

def _discard(s, key, ret):     try:         s.remove(key)     except keyerror:         return ret     return key      s = set([1,2,3]) ret = "not found"  key = 4  print _discard(s, key, ret), s  key = 3  print _discard(s, key, ret), s 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -