Implicit lists
Mark McEahern
marklists at mceahern.com
Thu Jan 30 10:37:08 EST 2003
[Alex Martelli]
> for x in aslist(list):
> whatever(x)
>
>
> How aslist is written is obviously quite secondary (at least,
> I _hope_ that's obvious...) -- all of its USES will be just as
> neat as the above example.
As a complement to what Alex wrote, I'd suggest writing unit tests that
document how you expect aslist to work with various types; e.g.,
import unittest
class test(unittest.TestCase):
def test_stringlike(self):
s = "foo"
alist = [for x in aslist(s)]
self.assertEquals(alist, [s])
...
etc.
// m
-
More information about the Python-list
mailing list