On 28 January 2013 2:44, : Oscar Benjamin [mailto:oscar.j.benja...@gmail.com wrote:
Please post in plain text (not html) as otherwise the code gets screwed up. ... Some people like to use regexes for everything. I prefer to try string methods first as I find them easier to understand. Here's my attempt: >>> junk_list = 'tmsh list net interface 1.3 media-ca \rpabilities\r\nnet >>> interface 1.3 {\r\n media-capabilities {\r\n none\r\n >>> auto\r\n 40000SR4-FD\r\n 10T-HD\r\n 100TX-FD\r\n >>> 100TX-HD\r\n 1000T-FD\r\n 40000LR4-FD\r\n 1000T-HD\r\n >>> }\r\n}\r\n' >>> junk_list = [s.strip() for s in junk_list.splitlines()] junk_list = >>> [s for s in junk_list if s == 'auto' or s[:2] in ('10', '40')] >>> junk_list ['auto', '40000SR4-FD', '10T-HD', '100TX-FD', '100TX-HD', '1000T-FD', '40000LR4-FD', '1000T-HD'] Does that do what you want? Oscar ***************************** Got it Oscar. Thank you for your respectful corrections and your solution. I used "Rich Text" which is what I thought was recommended by the list gurus at one point. Plain Text it is then. Your response definitely does the trick and I can use that as a base for the future. As per Joel's comment that it is a variation of questions I asked in the past, right you are. I had to put this away for a while and am picking it up again now. I will get string manipulation / RegEx educated. Thank You, Dave _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor