-
Notifications
You must be signed in to change notification settings - Fork 0
/
thoughts-on-pythons-iterators.html
66 lines (55 loc) · 3.64 KB
/
thoughts-on-pythons-iterators.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta id="keywords" name="keywords" content="">
<link id="stylesheet" rel="stylesheet" type="text/css" href="https://oskipa.github.io/theme/css/code.css"></link>
<link id="stylesheet" rel="stylesheet" type="text/css" href="https://oskipa.github.io/theme/css/site.css"></link>
</head>
<body>
<header class="header">
<h1 class="site-name">
<a class="home-link" href="https://oskipa.github.io">Dada</a><br />
|> Structures<br />
|> Algorithms</h1>
<nav>
<menu class="minimal-menu">
<li><a href="https://oskipa.github.io/pages/today-i-learned.html">til</a></li>
<li><a href="https://oskipa.github.io/pages/now.html">now</a></li>
<li><a href="https://oskipa.github.io/short_index.html">index</a></li>
<!--
<li><a href="category/log.html">web log<a></li>
<li><a href="">about<a></li>
<li><a href="">site map<a></li>
-->
</menu>
</nav>
</header>
<div class="container">
<div class="row">
<div class="col-md-8">
<h2>Thoughts on Python's iterators</h2>
<h3></h3>
<label>07 August, 2020</label>
<p>I just read <a href="https://dbader.org/blog/python-iterators">Dan Bader's blog on iterators</a> [1]. Iterators were this fuzzy concept that sort of made sense, yet never did. I understood that they were there and how to use them. I read the blog, I try the example, and it clicks.</p>
<p>The summary is that an iterator is an object that will give you one item from a collection at a time. Once it gets to the end, it signals that there are no more items. In Python it does this via a StopIteration exception. The "for x in" expression seems to know how to handle these iterators.</p>
<p>Once again, Python makes the complex easy to understand. I recall taking a C++ class. I got an A in the course. I still didn't feel confident with OOP. Then I spend some time writing a chip simulator using Python. And OOP clicked. It made sense.</p>
<p>Python sits in a weird place. It is both an academic and an industry language. It could be that this duality allows it to a balance between making things terse enough so you can get the intention quickly, yet not too terse that you can't understand. It worked like that 20 years ago. It still works today.</p>
<p>This example has made me think again about the Python Data Model that works along with those funky underscore methods like __iter__. They seem to be the key to this behavior. Also the key to a lot of Python's goodness. The Python Data Model will be the next think I tackle.</p>
<p>References:</p>
<p>[1] D. Bader. <em>Python Iterators: A Step-By-Step Introduction</em>. dbader.org. <a href="https://dbader.org/blog/python-iterators">https://dbader.org/blog/python-iterators</a> (accessed August 8, 2020)</p>
</div>
</div>
</div>
<footer class="footer">
<!-- <p class="about"><a href="http://hugoestr.github.io/blog/manifesto.html">About</a> --> <a href="https://oskipa.github.io/pages/about.html" >I am</a> a software developer. I code in Python, Ruby, Lisp, and many other languages. I like poetry, museums, and ukuleles. I try to guide my life on principles of dadaism and nonviolence.</p>
<p>
<a href="feeds/all.atom.xml">atom</a>
<!-- <a href="http://github.com/oskipa/">github</a> -->
</p>
<p>Artisanally built with <a href="https://blog.getpelican.com/">Pelican</a>. Content handcrafted in <a href="https://www.vim.org/" >Vim</a>. All hallucinations are human. 100% AI Free.</p>
</footer>
</body>
</html>