> [Jeff Epler]
> > Maybe something for sets like 'appendlist' ('unionset'?)
>
On Sat, Mar 19, 2005 at 04:18:43AM +0000, Raymond Hettinger wrote:
> I do not follow. Can you provide a pure python equivalent?
Here's what I had in mind:
$ python /tmp/unionset.py
Set(['set', 'self', 'since', 's', 'sys', 'source', 'S', 'Set', 'sets',
'starting'])
#------------------------------------------------------------------------
try:
set
except:
from sets import Set as set
def unionset(self, key, *values):
try:
self[key].update(values)
except KeyError:
self[key] = set(values)
if __name__ == '__main__':
import sys, re
index = {}
# We need a source of words. This file will do.
corpus = open(sys.argv[0]).read()
words = re.findall('\w+', corpus)
# Create an index of the words according to the first letter.
# repeated words are listed once since the values are sets
for word in words:
unionset(index, word[0].lower(), word)
# Display the words starting with 'S'
print index['s']
#------------------------------------------------------------------------
Jeff
pgpecFFOsSmDH.pgp
Description: PGP signature
-- http://mail.python.org/mailman/listinfo/python-list
