File traversing
Karl Knechtel
zahlman at gmail.com
Mon Apr 16 16:50:40 EDT 2012
On Sun, Apr 15, 2012 at 5:51 AM, Chris Angelico <rosuav at gmail.com> wrote:
>
> (You may also want to consider using the 'with' statement to guarantee
> a timely closing of the file. Outside the scope of this mail though.)
>
> I think this list is just to collect unique entries, yes? If so, a set
> may be more to your liking. Check out:
> http://docs.python.org/py3k/library/stdtypes.html#set
>
> <http://mail.python.org/mailman/listinfo/python-list>
In cases like this I like to just show the final code after making all the
changes, and let the student ask questions :)
with open('/bah') as res_own_file:
all_res = set(line.strip().replace(' ', '').split(':')[1] for line in
res_own_file if ':' in line)
--
~Zahlman {:>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120416/480edef0/attachment.html>
More information about the Python-list
mailing list