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).
[snip]
%
%  Number of Instances: 8124
%
%  Number of Attributes: 22 (all nominally valued)
%
[snip]
@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'}
[snip]
'x','s','n','t','p','f','c','n','k','e','e','s','s','w','w','p','w','o','p',
'k','s','u','p'
'x','s','y','t','a','f','c','b','k','e','c','s','s','w','w','p','w','o','p',
'n','n','g','e'
'b','s','w','t','l','f','c','b','n','e','c','s','s','w','w','p','w','o','p',
'n','n','m','e'
'x','y','w','t','p','f','c','n','n','e','e','s','s','w','w','p','w','o','p',
'k','s','u','p'
[snip]

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
few
> 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