Python, how to remove or replace some value in a set's

I found this example very usable
[code language="python"]
print('"discard" method for remove particular string value from list\n')
words = ['test', 'many', 'makeword', 'jazz', 'tube'] # list

words = set(words)
for word in {"MAKEWORD", "Makeword", "makeword"}:
words.discard(word)
print words

print('\nAnd now we\'re going to "discard" from set number of \
words("MAKEWORD", "Makeword", "makeword", plus using "replace" some string values from tuple\n')

words = ('test', 'many[br]', 'makeword', 'jazz[br]', 'doc', 'word', 'words') # tuple

words = [w.replace('[br]', '<br/>') for w in words]
words = set(words) - {"MAKEWORD", "Makeword", "makeword"}
print words
[/code]
Also, it possible remove elements with set.remove(), but this method will call KeyError exception if deleted element hasn't included in set(list or tuple)

Comments

Popular posts from this blog

Robot Framework vs Cucumber

Performance Testing of RESTful APIs Using JMeter

Verification displayed number of rows inside table by Robot Framework