Splitting a list of strings

Greg Ewing see_reply_address at something.invalid
Wed Sep 18 02:14:08 EDT 2002


Sean Ross wrote:

> 
> What I'm interested in knowing is, can I extract all of the "attribute"
> strings from lines in such a way that I get my list of "attribute" strings,
> but all of those strings have been removed from lines as well, all at the
> same time?


     attributes = []
     data = []
     for line in lines:
       c = line[0]
       if c == "@":
         attributes.append(line)
       elif c <> "%":
         data.append(line)


-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list