<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Data Structures and Functions on kodkod | Intro Course</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/</link><description>Recent content in Data Structures and Functions on kodkod | Intro Course</description><generator>Hugo</generator><language>en</language><copyright>מבואות קודקוד</copyright><atom:link href="https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/index.xml" rel="self" type="application/rss+xml"/><item><title>list: Creating, Accessing, Adding, Removing, Searching and Looping</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/01-list/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/01-list/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;list&lt;/strong&gt; is the most common data structure in Python. We already used it briefly. Today we will learn it properly:&lt;/p&gt;</description></item><item><title>tuple and set: a Fixed Record and a Collection Without Duplicates</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/02-tuple-and-set/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/02-tuple-and-set/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;Two more data structures, each with a &amp;ldquo;superpower&amp;rdquo; of its own:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;tuple&lt;/strong&gt; — like a list, but &lt;strong&gt;fixed&lt;/strong&gt;: it cannot be changed after it is created.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;set&lt;/strong&gt; — a collection &lt;strong&gt;without duplicates&lt;/strong&gt; and without order, which lets you check very quickly whether a value is in it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;tuple&lt;/strong&gt; suits data that represents &lt;strong&gt;one record with a fixed structure&lt;/strong&gt;: a point &lt;code&gt;(x, y)&lt;/code&gt;, a date &lt;code&gt;(2026, 10, 6)&lt;/code&gt;, a row from a Database &lt;code&gt;(7, &amp;quot;Dana&amp;quot;, 24)&lt;/code&gt;. In the backend and databases topics, &lt;strong&gt;every row that comes back from the Database will arrive as a tuple!&lt;/strong&gt; Being fixed guarantees that no code changes a record &amp;ldquo;by mistake&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;set&lt;/strong&gt; suits cases where you want &lt;strong&gt;uniqueness&lt;/strong&gt;: how many &lt;strong&gt;different&lt;/strong&gt; users visited the site today? Which tags does a post have? Who is registered for two courses at once?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="explanation-from-the-basics"&gt;Explanation from the basics&lt;/h2&gt;
&lt;h3 id="tuple"&gt;tuple&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;tuple&lt;/strong&gt; is an &lt;strong&gt;ordered&lt;/strong&gt; sequence of values, &lt;strong&gt;that cannot be changed&lt;/strong&gt; (Immutable). Once it is created, you cannot add, remove or replace items.&lt;/p&gt;</description></item><item><title>dict: Key and Value</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/03-dict/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/03-dict/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;A &lt;strong&gt;dict&lt;/strong&gt; (Dictionary) is a structure that holds &lt;strong&gt;pairs of a key and a value&lt;/strong&gt;. Instead of accessing by position (&lt;code&gt;[0]&lt;/code&gt;), you access by &lt;strong&gt;name&lt;/strong&gt; (&lt;code&gt;[&amp;quot;name&amp;quot;]&lt;/code&gt;).&lt;/p&gt;</description></item><item><title>Slicing, Mutable versus Immutable, and is versus ==</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/04-slicing-mutability-identity/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/04-slicing-mutability-identity/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Slicing&lt;/strong&gt; — how to cut out part of a list, a tuple or a string.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mutable&lt;/strong&gt; versus &lt;strong&gt;Immutable&lt;/strong&gt; — what can be changed and what cannot, and why it matters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;References&lt;/strong&gt; — what happens when you write &lt;code&gt;b = a&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;is&lt;/code&gt; versus &lt;code&gt;==&lt;/code&gt;&lt;/strong&gt; — &amp;ldquo;the same value&amp;rdquo; versus &amp;ldquo;exactly the same object&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Slicing&lt;/strong&gt; is everywhere: the first 10 results, the last 3 characters of a card number (&lt;code&gt;****1234&lt;/code&gt;), &amp;ldquo;page 2&amp;rdquo; of a list.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mutable&lt;/strong&gt; is the source of one of the most confusing bugs in Python: &amp;ldquo;I changed one list, and suddenly the second one changed too!&amp;rdquo;. Understanding this topic prevents hours of debugging. And in the OOP topic, objects of classes behave exactly like this.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="explanation-from-the-basics"&gt;Explanation from the basics&lt;/h2&gt;
&lt;h3 id="slicing"&gt;Slicing&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Slicing&lt;/strong&gt; creates a &lt;strong&gt;new sequence&lt;/strong&gt; from part of an existing sequence:&lt;/p&gt;</description></item><item><title>Functions in Depth: Default Values, Functions as Objects, *args, **kwargs and Lambda</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/05-functions-args-kwargs-lambda/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/05-functions-args-kwargs-lambda/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;In the clean code and debugging topic we learned the basics: &lt;code&gt;def&lt;/code&gt;, parameters, &lt;code&gt;return&lt;/code&gt;. Today we will learn a few abilities that make functions much more flexible:&lt;/p&gt;</description></item><item><title>Scope: Local, Enclosing, Global and Built-in (LEGB)</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/06-scope-legb/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/06-scope-legb/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt; = &lt;strong&gt;the area of the code where a name (a variable or a function) is known&lt;/strong&gt;. We will learn:&lt;/p&gt;</description></item><item><title>Pure Functions and Side Effects</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/07-pure-functions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/07-pure-functions/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;What a &lt;strong&gt;Pure Function&lt;/strong&gt; is.&lt;/li&gt;
&lt;li&gt;What a &lt;strong&gt;Side Effect&lt;/strong&gt; is — and which kinds exist.&lt;/li&gt;
&lt;li&gt;The trap of &lt;strong&gt;changing a list that was received as a parameter&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;How to write a &lt;strong&gt;pure version&lt;/strong&gt; of a function.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;Here is a function that looks innocent:&lt;/p&gt;</description></item><item><title>Higher-Order Functions: Functions That Receive and Return Functions</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/08-higher-order-functions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/08-higher-order-functions/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;What a &lt;strong&gt;Higher-Order Function&lt;/strong&gt; is.&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;pass a function as a parameter&lt;/strong&gt; — and why without brackets.&lt;/li&gt;
&lt;li&gt;The built-in functions &lt;strong&gt;&lt;code&gt;map&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;filter&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;key&lt;/code&gt;&lt;/strong&gt; parameter of &lt;code&gt;sorted&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;min&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A function that returns a function&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;Two almost identical functions:&lt;/p&gt;</description></item><item><title>Nested Functions, Closures and nonlocal</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/09-nested-functions-nonlocal/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/09-nested-functions-nonlocal/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Nested Function&lt;/strong&gt; — a function defined inside a function.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Enclosing&lt;/strong&gt; — the E of LEGB, up close.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Closure&lt;/strong&gt; — a function that &amp;ldquo;remembers&amp;rdquo; variables.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;nonlocal&lt;/code&gt;&lt;/strong&gt; — how to change a variable of the enclosing function.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A private helper function:&lt;/strong&gt; sometimes a function needs a small helper function that belongs &lt;strong&gt;only&lt;/strong&gt; to it. There is no reason for it to be global and get mixed up with the rest of the code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Functions that remember state:&lt;/strong&gt; in the previous lesson we saw that &lt;code&gt;make_multiplier(2)&lt;/code&gt; returns a function that &amp;ldquo;remembers&amp;rdquo; the number 2. Today we will understand how it works — and how to build a counter, an accumulator or a cache &lt;strong&gt;without&lt;/strong&gt; &lt;code&gt;global&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="explanation-from-the-basics"&gt;Explanation from the basics&lt;/h2&gt;
&lt;h3 id="a-function-inside-a-function"&gt;A function inside a function&lt;/h3&gt;
&lt;p&gt;You can define a &lt;code&gt;def&lt;/code&gt; inside a &lt;code&gt;def&lt;/code&gt;. The inner function:&lt;/p&gt;</description></item><item><title>Decorators: Adding Behavior to a Function Without Touching It</title><link>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/10-decorators/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://intro-kodkod-6.nm-ambition.com/en/docs/python-data-functions/10-decorators/</guid><description>&lt;h2 id="what-will-we-learn"&gt;What will we learn?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;What a &lt;strong&gt;Decorator&lt;/strong&gt; is and why it is useful.&lt;/li&gt;
&lt;li&gt;How to build a Decorator: a function that receives a function and returns a &lt;strong&gt;wrapper&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;@&lt;/code&gt;&lt;/strong&gt; syntax.&lt;/li&gt;
&lt;li&gt;A wrapper that fits &lt;strong&gt;any&lt;/strong&gt; function, with &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="why-do-we-need-this"&gt;Why do we need this?&lt;/h2&gt;
&lt;p&gt;We want to print a message every time a function is called — for debugging:&lt;/p&gt;</description></item></channel></rss>