<div dir="ltr"><div>For those wondering what it means when someone say Python code is idiomatic or Pythonic, here is a video that I thought was helpful by a great speaker / Python core developer named Raymond Hettinger:<br><a href="https://www.youtube.com/watch?v=OSGv2VnC0go">https://www.youtube.com/watch?v=OSGv2VnC0go</a><br></div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 24, 2014 at 7:17 PM,  <span dir="ltr"><<a href="mailto:jep200404@columbus.rr.com" target="_blank">jep200404@columbus.rr.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
very common code pattern in many programming languages:<br>
<br>
    loop executes n times<br>
    first value is zero (NOT 1)<br>
    last value in loop is n-1 (NOT n)<br>
    test is < n.<br>
        comparison is <, not <=<br>
        compared value is n, not n-1<br>
    next value is made at end of loop<br>
<br>
    >>> def do_n_times(n):<br>
    ...     i = 0<br>
    ...     while i < n:<br>
    ...         print i<br>
    ...         i += 1<br>
    ...<br>
    >>> do_n_times(3)<br>
    0<br>
    1<br>
    2<br>
    >>><br>
<br>
A more Pythonic way of doing the above follows.<br>
<br>
    >>> def do_n_times(n):<br>
    ...     for i in range(n):<br>
    ...         print i<br>
    ...<br>
    >>> do_n_times(3)<br>
    0<br>
    1<br>
    2<br>
    >>><br>
<br>
i is often used to index into data that one is going through.<br>
However in Python, one can often go through data one thing at a time,<br>
without have an index,<br>
so one often does something like the following fake Python code:<br>
<br>
    >>> def do_stuff(data_collection):<br>
    ...     for thing in data_collection:<br>
    ...         print thing<br>
    ...<br>
    >>> do_stuff(['hello', 3.14159+2.71828j, True, 42])<br>
    hello<br>
    (3.14159+2.71828j)<br>
    True<br>
    42<br>
    >>><br>
_______________________________________________<br>
CentralOH mailing list<br>
<a href="mailto:CentralOH@python.org">CentralOH@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/centraloh" target="_blank">https://mail.python.org/mailman/listinfo/centraloh</a><br>
</blockquote></div><br></div></div></div></div></div>