Newbie array question
danb_83 at yahoo.com
Sun Jun 13 01:17:32 CEST 2004
nhirsh2 at ieee.org (Neale) wrote in message news:<2d7af4f8.0406112032.4cb4438a at posting.google.com>...
> My first task with Python is to scan multiple small text files and
> "batch together" those records with a "5" or "6" in column 2, and then
> save as a new file. The records are 256 characters. I know it sounds
> like a homework problem, but it's not.
Assuming that all your records are strings in an array called
"records", you can discard the ones without a '5' or '6' in column 2
(column 1 in 0-based indexing) with:
records = [r for r in records if r in ('5', '6')]
More information about the Python-list