I'm wondering what is the Python way to perform the following - Given a set :
s = {'s1','s2','s3'}
I would like to perform something like :
s.addToAll('!')
to get
{'s1!','s2!','s3!'}
Thanks!
I'm wondering what is the Python way to perform the following - Given a set :
s = {'s1','s2','s3'}
I would like to perform something like :
s.addToAll('!')
to get
{'s1!','s2!','s3!'}
Thanks!
For an actual set:
>>> s = {'s1','s2','s3'}
>>> {x + '!' for x in s}
set(['s1!', 's2!', 's3!'])
That method is 2.7+, If you are using Python 2.6 you would have to do this instead:
>>> s = set(['s1','s2','s3'])
>>> set(x + '!' for x in s)
set(['s1!', 's2!', 's3!'])
You can try this:
>>> s = ['s1','s2','s3']
>>> list(i + '!' for i in s)