Loop Like a Native


Thanks for posting this. I picked up a few useful hints; particularly I'd missed the rather handy enumerate function. Also, I'll be thinking more of using generators to flatten nested loops into a single loop.
I really like your format for blog slides. So much more useful than just the slides, maybe even a video.
Piotr Dobrogost 3:42 PM on 18 Mar 2013
To loop one has to have iterable in the first place whereas often we get scalar value instead. That's why I find it useful to have this kind of "adapter":
    def as_iterable(input,
        if isinstance(input, empty_types):
            return ()
            if isinstance(input, scalar_types):
                return (input,)
                return iter(input)
Superb article/talk. Thanks.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.