Splitting a list of strings

Sean Ross sross at connectmail.carleton.ca
Tue Sep 17 22:55:52 EDT 2002

Okay. Here is some representative sample data:

%  Relevant Information:
%     This data set includes descriptions of hypothetical samples
%     corresponding to 23 species of gilled mushrooms in the Agaricus and
%     Lepiota Family (pp. 500-525).
%  Number of Instances: 8124
%  Number of Attributes: 22 (all nominally valued)
@attribute 'cap-shape' { 'b', 'c', 'f', 'k', 's', 'x'}
@attribute 'cap-surface' { 'f', 'g', 's', 'y'}
@attribute 'cap-color' { 'b', 'c', 'e', 'g', 'n', 'p', 'r', 'u', 'w', 'y'}

So, essentially, there are three types of strings in the file: comments,
attribute descriptors, and data. I'm pulling out the attribute descriptor
and data strings and storing them in separate lists. I'll be doing stuff
with those latter; making a decision tree, for instance. Anyway, the code
I've written does what I need, but I'm thinking there may be a more
efficient method. Hence, the post.

As for str, I agree and the name has been changed. Thank you.

"Mark McEahern" <marklists at mceahern.com> wrote in message
news:mailman.1032309381.3626.python-list at python.org...
> > I need to read a list of strings from a file[...]
> For those of us who are lazy and lacking in imagination, why not share a
> lines of representative sample data?
> // m
> p.s.  Don't use str as the name of a variable, you'll clobber the builtin
> str.
> -

More information about the Python-list mailing list