[Baypiggies] Pythonic way to iterate over two lists?
simeonf at gmail.com
Tue Jun 7 07:43:41 CEST 2011
I taught a Python Fundamentals class last week for Marakana and
noticed that other programmers coming from languages that are not
specifically functionally oriented were unfamiliar with zip as a
concept. Most explanations of zip tend to focus on the two case (given
two lists it returns paired elements) and the more general Python
documentation explanation was met with thoughtful incomprehension:
>This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.
When I paraphrased this as "zip will take arguments that represent
rows of input data and return a list whose elements are the columns of
the input data" mental lightbulbs went on all over the room. YMMV but
I thought it made for an intuitive explanation... It also leads me to
think more naturally of possible applications of zip and iterative
More information about the Baypiggies