<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3524535260938031835</id><updated>2026-04-03T12:26:49.471-07:00</updated><category term="Python"/><category term="tutorial"/><category term="forfun"/><category term="linux"/><category term="inspiration"/><category term="development"/><category term="game"/><category term="oauth"/><category term="Java"/><category term="android"/><category term="manjaro"/><category term="news"/><category term="book"/><category term="opensource"/><category term="django"/><category term="operating system"/><category term="security"/><category term="sqlite"/><category term="ubuntu"/><category term="xfce"/><title type='text'>my little note</title><subtitle type='html'>for better future</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>51</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-1212845935035809678</id><published>2015-11-03T03:33:00.001-08:00</published><updated>2015-11-24T17:49:47.694-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>David Beazley - Modules and Packages: Live and Let Die!</title><content type='html'>If you are Python developer don&#39;t miss this section from PyCon 2015 by &lt;a href=&quot;http://www.dabeaz.com/&quot;&gt;David Beazly&lt;/a&gt;. This section is important for every python developer.&lt;br /&gt;
Why it&#39;s important? if you don&#39;t know about how python module, namespace and packaging in general manner you will die :-).&lt;br /&gt;
This section not talk about how to create package, but more general about what is package and module it self.&lt;br /&gt;
Good explanations by David, this section also compare which one that should and shouldn&#39;t do by developer. &lt;br /&gt;
for more information you can watch PyCon 2015 By David Beazley - Modules and Packages: Live and Let Die!&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;270&quot; src=&quot;https://www.youtube.com/embed/0oTh1CXRaQ0&quot; width=&quot;480&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/1212845935035809678/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/11/david-beazley-modules-and-packages-live.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/1212845935035809678'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/1212845935035809678'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/11/david-beazley-modules-and-packages-live.html' title='David Beazley - Modules and Packages: Live and Let Die!'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/0oTh1CXRaQ0/default.jpg" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-7705083709193974022</id><published>2015-11-02T20:42:00.000-08:00</published><updated>2015-11-24T17:49:56.562-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><title type='text'>Android HTML5 App, how really it&#39;s?</title><content type='html'>In this post I just want to share HTML5 development, it&#39;s not using framework like apache cordova or something else. I just want to share how to communicate or interfacing between javascript and android java native code.&lt;br /&gt;
&lt;br /&gt;
When I wrote this post, I use Android Studio Version 1.4.&lt;br /&gt;
&lt;br /&gt;
For complete project you can download from this link&amp;nbsp; &lt;a href=&quot;https://www.dropbox.com/s/02mor7925l1l3bg/MyApplication.zip?dl=0&quot;&gt;https://www.dropbox.com/s/02mor7925l1l3bg/MyApplication.zip?dl=0&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Create new project with no activity using android studio&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE8DKDNXv5USfkuWyegQugMadRHARcvr-lMSxXYgHg1AfGvru2tiAH7xVPWAd-orqdFkd2vRMwXDUuy4XF9QM-WguGYzh47AXcjZvG1_gda7ORAIwKN5s1KUWzFTPzCpSMa2XgV3yBP5M/s1600/Screen+Shot+2015-11-03+at+10.50.13+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;258&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE8DKDNXv5USfkuWyegQugMadRHARcvr-lMSxXYgHg1AfGvru2tiAH7xVPWAd-orqdFkd2vRMwXDUuy4XF9QM-WguGYzh47AXcjZvG1_gda7ORAIwKN5s1KUWzFTPzCpSMa2XgV3yBP5M/s400/Screen+Shot+2015-11-03+at+10.50.13+AM.png&quot; width=&quot;400&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Edit AndroidManifest.xml to be like this,&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;br /&gt;&amp;lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; package=&quot;com.example.amru.myapplication&quot; &amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;application&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; android:allowBackup=&quot;true&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; android:icon=&quot;@mipmap/ic_launcher&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; android:label=&quot;@string/app_name&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; android:supportsRtl=&quot;true&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; android:theme=&quot;@style/AppTheme&quot; &amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;activity android:name=&quot;.MainActivity&quot; &amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;intent-filter&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;action android:name=&quot;android.intent.action.MAIN&quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/intent-filter&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/activity&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/application&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/manifest&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Then add android assets folder inside main, same level with android res folder,&lt;br /&gt;
Create assets folder with some folder inside assets folder:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;html (for html page)&lt;/li&gt;
&lt;li&gt;css (for css style)&lt;/li&gt;
&lt;li&gt;js (for javascript function)&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRPCELL6BcndREqexsYjF7uzDF4Z9Y1D1WKtmzGGthbEBsayx5wWVNuwsQpeIKV2nEzguIWzO6zUt0JcVFPN2SE4tePqYKKf1ffPSZvlpXQIuJV-CeieciJ1Yk4SjQp7dwMPALi7CixCM/s1600/Screen+Shot+2015-11-03+at+10.56.41+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRPCELL6BcndREqexsYjF7uzDF4Z9Y1D1WKtmzGGthbEBsayx5wWVNuwsQpeIKV2nEzguIWzO6zUt0JcVFPN2SE4tePqYKKf1ffPSZvlpXQIuJV-CeieciJ1Yk4SjQp7dwMPALi7CixCM/s640/Screen+Shot+2015-11-03+at+10.56.41+AM.png&quot; width=&quot;356&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Create HTMLUtil class for read html page to parse .html page.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBjebBF2khB4qo0uRoT4gT_OlN9BqI9uh5iZwDbpOrlx8A6-ukPKSoE9yVuiEm72xxZg-Rpd2_5TPXClImNf2YAcBh0TK3YfYQEU_mUYchyEkpnzxbsCxjEvG4YvP9dPtID1iejtSegK8/s1600/Screen+Shot+2015-11-03+at+11.02.34+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;191&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBjebBF2khB4qo0uRoT4gT_OlN9BqI9uh5iZwDbpOrlx8A6-ukPKSoE9yVuiEm72xxZg-Rpd2_5TPXClImNf2YAcBh0TK3YfYQEU_mUYchyEkpnzxbsCxjEvG4YvP9dPtID1iejtSegK8/s400/Screen+Shot+2015-11-03+at+11.02.34+AM.png&quot; width=&quot;400&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Then put this line into HTMLUtil&amp;nbsp; class&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;package com.example.amru.myapplication;&lt;br /&gt;&lt;br /&gt;import android.content.Context;&lt;br /&gt;import android.content.res.AssetManager;&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.io.InputStream;&lt;br /&gt;import java.io.InputStreamReader;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&amp;nbsp;* Created by amru on 10/28/15.&lt;br /&gt;&amp;nbsp;*/&lt;br /&gt;public class HTMLUtil {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static String ASSET_DIR = &quot;file:///android_asset/&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static String HTML_PREFIX = &quot;.html&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static String HTML_DIR = &quot;html/&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static String HTML_MIME = &quot;text/html&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static String UTF8_ENCODING = &quot;UTF-8&quot;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private Context _context;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public HTMLUtil(Context context){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this._context = context;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // filename without .html prefix&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String readHTML(String filename){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; StringBuilder html = new StringBuilder();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AssetManager assetManager = this._context.getAssets();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InputStream inputStream = assetManager.open(HTMLUtil.HTML_DIR + filename + HTMLUtil.HTML_PREFIX);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String line;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while((line = bufferedReader.readLine()) != null){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; html.append(line);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }catch (IOException e){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.printStackTrace();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return html.toString();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/span&gt;&lt;/blockquote&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Create JsInterface class, and put this line&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;package com.example.amru.myapplication;&lt;br /&gt;&lt;br /&gt;import android.app.AlertDialog;&lt;br /&gt;import android.content.Context;&lt;br /&gt;import android.content.DialogInterface;&lt;br /&gt;import android.webkit.JavascriptInterface;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&amp;nbsp;* Created by amru on 10/28/15.&lt;br /&gt;&amp;nbsp;*/&lt;br /&gt;public class JsInterface {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private Context _context;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public JsInterface(Context context){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this._context = context;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // don&#39;t forget user @JavascriptInterface if you want call it from javascript&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // this is mandatory start from api 16&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @JavascriptInterface&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void sayHello(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AlertDialog.Builder alert = new AlertDialog.Builder(this._context);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert.setTitle(&quot;halo&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert.setMessage(&quot;this from native dialog...&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert.setNegativeButton(&quot;Close&quot;, new DialogInterface.OnClickListener() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void onClick(DialogInterface dialog, int which) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dialog.dismiss();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert.show();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // parameter should be in json&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // func is function name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // call javascript function from native activity&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // need call from post runnable, make sure it&#39;s thread safe :)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void callJS(String func, String param){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final StringBuilder stringBuilder = new StringBuilder();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stringBuilder.append(&quot;javascript:&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stringBuilder.append(func);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stringBuilder.append(&quot;(&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stringBuilder.append(param);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stringBuilder.append(&quot;)&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.post(new Runnable() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void run() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.loadUrl(stringBuilder.toString());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
On MainActivity class put this line,&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;package com.example.amru.myapplication;&lt;br /&gt;&lt;br /&gt;import android.app.Activity;&lt;br /&gt;import android.os.Bundle;&lt;br /&gt;import android.view.View;&lt;br /&gt;import android.webkit.WebChromeClient;&lt;br /&gt;import android.webkit.WebView;&lt;br /&gt;&lt;br /&gt;public class MainActivity extends Activity {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private HTMLUtil _mHTMLUtil;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static WebView WEB_VIEW;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected void onCreate(Bundle savedInstanceState) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super.onCreate(savedInstanceState);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this._mHTMLUtil = new HTMLUtil(this);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW = new WebView(this);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.setWebChromeClient(new WebChromeClient());&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.getSettings().setJavaScriptEnabled(true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.getSettings().setAllowContentAccess(true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.getSettings().setAllowFileAccess(true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.getSettings().setBuiltInZoomControls(false);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.setWebChromeClient(new WebChromeClient());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.loadDataWithBaseURL(HTMLUtil.ASSET_DIR + HTMLUtil.HTML_DIR,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this._mHTMLUtil.readHTML(&quot;page&quot;),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HTMLUtil.HTML_MIME,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HTMLUtil.UTF8_ENCODING,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; null);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setContentView(MainActivity.WEB_VIEW);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // register JsInterface class as native interface&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // we can call via NativeInterface.method_name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainActivity.WEB_VIEW.addJavascriptInterface(new JsInterface(this), &quot;NativeInterface&quot;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // let&#39;s try to call javascript from native&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JsInterface.callJS(&quot;callMeJava&quot;, &quot;&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
&lt;br /&gt;
For testing the HTML5 App, we need to create some html pages and javascript code. Create page.html, fn.js inside html folder and js folder.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6GNlJ6yiA89ZLyILojEo3-DfVBETdr-Clip9758KQjLPLzqccyv90MB0Pz8IaU9CSk020Q5hZVAh9l-Y-4mCe89tTBZbBdz4Kh1UtiCE6L5VwZMNh4chKsN1-doeMNhUkdOSyhUAfa1A/s1600/Screen+Shot+2015-11-03+at+11.17.06+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6GNlJ6yiA89ZLyILojEo3-DfVBETdr-Clip9758KQjLPLzqccyv90MB0Pz8IaU9CSk020Q5hZVAh9l-Y-4mCe89tTBZbBdz4Kh1UtiCE6L5VwZMNh4chKsN1-doeMNhUkdOSyhUAfa1A/s400/Screen+Shot+2015-11-03+at+11.17.06+AM.png&quot; width=&quot;280&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
page.html&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;head&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script type=&quot;text/javascript&quot; src=&quot;file:///android_asset/js/fn.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/head&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;body&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;button id=&quot;mybutton&quot; onclick=&quot;testAlert();&quot;&amp;gt;click !&amp;lt;/button&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
fn.js&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;// call native interface function&lt;br /&gt;function testAlert(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NativeInterface.sayHello();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// this will call from java native&lt;br /&gt;function callMeJava(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(&#39;call js function from java native.&#39;);&lt;br /&gt;}&lt;/span&gt; &lt;/blockquote&gt;
&lt;br /&gt;
Then, we can start to test the app prototype. When app loaded it will trigger callMeJava function from fn.js. The method call from oncreate activity just test case only.&lt;br /&gt;
&lt;br /&gt;
through this line on MainActivity&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;// let&#39;s try to call javascript from native&lt;br /&gt;JsInterface.callJS(&quot;callMeJava&quot;, &quot;&quot;);&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT_hDOtzf55lKFVcsIun1JSmcLl05NdJyROIuiVmzt9dWJJRIt8dKa6UZLWFfsmhvQulAqyFDcPW_fdpPD2lfzCIShyd1n_5-QigSUzYAnxMo-K79M6I8P_c0tp_p04JRIxdz9_hCTYgU/s1600/Screen+Shot+2015-11-03+at+11.26.20+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT_hDOtzf55lKFVcsIun1JSmcLl05NdJyROIuiVmzt9dWJJRIt8dKa6UZLWFfsmhvQulAqyFDcPW_fdpPD2lfzCIShyd1n_5-QigSUzYAnxMo-K79M6I8P_c0tp_p04JRIxdz9_hCTYgU/s400/Screen+Shot+2015-11-03+at+11.26.20+AM.png&quot; width=&quot;347&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Let&#39;s test call from javascript to native,&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Through this line (JsInterface class)&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
// call native interface function&lt;/div&gt;
function testAlert(){&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; NativeInterface.sayHello();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this will call from java native&lt;br /&gt;
function callMeJava(){&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(&#39;call js function from java native.&#39;);&lt;br /&gt;
} &lt;/blockquote&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghaXitC9xUPnvBPeDs7CMYLk-oUt2WFIoiT2YOurZtTlDb-sW59LNq-8z8E-_f7I4rNWkp8J4t1jvq6bQz0a6iP2dnO5TQ5eTnsPRtSLWMyGYwnqHgOTdZDFvUrHk5R0sxmVit1agIYXE/s1600/Screen+Shot+2015-11-03+at+11.29.21+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghaXitC9xUPnvBPeDs7CMYLk-oUt2WFIoiT2YOurZtTlDb-sW59LNq-8z8E-_f7I4rNWkp8J4t1jvq6bQz0a6iP2dnO5TQ5eTnsPRtSLWMyGYwnqHgOTdZDFvUrHk5R0sxmVit1agIYXE/s400/Screen+Shot+2015-11-03+at+11.29.21+AM.png&quot; width=&quot;352&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-T7nq64FRlDibMplMwj9UkSbAczn2JAqsbonPbbPkyQK6tSZhOTzbeYHsEm_LmU4fwYrjuL48cIm7Rz6EkGwCg5WvEcP6Ycb4wjtEJ67dLD-mwWolSJEKnAdBU9gslfdbAG6E0zZMJXk/s1600/Screen+Shot+2015-11-03+at+11.29.26+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-T7nq64FRlDibMplMwj9UkSbAczn2JAqsbonPbbPkyQK6tSZhOTzbeYHsEm_LmU4fwYrjuL48cIm7Rz6EkGwCg5WvEcP6Ycb4wjtEJ67dLD-mwWolSJEKnAdBU9gslfdbAG6E0zZMJXk/s400/Screen+Shot+2015-11-03+at+11.29.26+AM.png&quot; width=&quot;357&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Thanks.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/7705083709193974022/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/11/android-html5-app-how-really-its.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/7705083709193974022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/7705083709193974022'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/11/android-html5-app-how-really-its.html' title='Android HTML5 App, how really it&#39;s?'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE8DKDNXv5USfkuWyegQugMadRHARcvr-lMSxXYgHg1AfGvru2tiAH7xVPWAd-orqdFkd2vRMwXDUuy4XF9QM-WguGYzh47AXcjZvG1_gda7ORAIwKN5s1KUWzFTPzCpSMa2XgV3yBP5M/s72-c/Screen+Shot+2015-11-03+at+10.50.13+AM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-8316551612859140255</id><published>2015-10-27T22:30:00.000-07:00</published><updated>2015-11-24T17:49:25.313-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python Access Java Through JNIus</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimEAfkUoqmsxD49k0K5Db3L8qcp5eNM9PqdCOsimE7fWpd8RdBJBvOyDqZJcjOBzaR1F7UX2o08WLOSdzHv6o6ZIzB-KVbBhU_QYfqDjBtwQXzRI5oiDl-eeSqHJ-mMdVx6WTWfaygYRc/s1600/python-mobile.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;130&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimEAfkUoqmsxD49k0K5Db3L8qcp5eNM9PqdCOsimE7fWpd8RdBJBvOyDqZJcjOBzaR1F7UX2o08WLOSdzHv6o6ZIzB-KVbBhU_QYfqDjBtwQXzRI5oiDl-eeSqHJ-mMdVx6WTWfaygYRc/s400/python-mobile.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Can python access java library or class?, yes it&#39;s possible. There are some project to do this, the popular one is PyJNIus and this project under &lt;a href=&quot;http://kivy.org/&quot;&gt;Kyvi&lt;/a&gt; project &lt;a href=&quot;https://github.com/kivy/pyjnius&quot;&gt;https://github.com/kivy/pyjnius&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
How it&#39;s work? PyJnius wrap java using JNI call so python can call it, don&#39;t worry if you don&#39;t know about it. Me to :-)&lt;br /&gt;
&lt;br /&gt;
To install PyJNIus, we need to install&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&amp;nbsp;Java JDK installed (OpenJDK will do)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Python 3.4 (In this case I use 3.4 version)&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Setup JAVA_HOME environment&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Setup JRE_HOME environment&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
After install python, we need to install &lt;a href=&quot;http://cython.org/&quot;&gt;cython&lt;/a&gt;, use pip or easy install. In this case I use pip.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
$ sudo pip install cython&lt;/blockquote&gt;
After cython installed, then install PyJNIus through&amp;nbsp; php or easy install. In this case I use pip&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
$ sudo pip install PyJnius&lt;/blockquote&gt;
After PyJnius installed then try import jnius from python, and let learn little thing about calling java from python.&lt;br /&gt;
&lt;br /&gt;
On linux should be no problem when importing jnius,&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35) &lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from jnius import autoclass&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; &lt;/blockquote&gt;
But on OSX we sometime meet this error when import jnius&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Traceback (most recent call last):&lt;br /&gt;
&amp;nbsp; File &quot;&amp;lt;stdin&amp;gt;&quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
&amp;nbsp; File &quot;/Users/barry/anaconda/envs/ovation-testing/lib/python2.7/site-packages/ovation/__init__.py&quot;, line 8, in &amp;lt;module&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; from jnius import autoclass, cast, JavaException&lt;br /&gt;
&amp;nbsp; File &quot;/Users/barry/anaconda/envs/ovation-testing/lib/python2.7/site-packages/jnius/__init__.py&quot;, line 12, in &amp;lt;module&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; from .jnius import *&lt;br /&gt;
ImportError: dlopen(/Users/barry/anaconda/envs/ovation-testing/lib/python2.7/site-packages/jnius/jnius.so, 2): Library not loaded: @rpath/libjvm.dylib&lt;br /&gt;
&amp;nbsp; Referenced from: /Users/barry/anaconda/envs/ovation-testing/lib/python2.7/site-packages/jnius/jnius.so&lt;br /&gt;
&amp;nbsp; Reason: image not found &lt;/blockquote&gt;
If you found that problem, you need to add this to .profile in your home file, and add this line then restart your terminal then try again to import jnius.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(/usr/libexec/java_home)/jre/lib/server &lt;/blockquote&gt;
now you can import jnius on python interpreter.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;On windows, I have no luck to install PyJnius through pip or easy install using MinGW as compiler. But I still struggling with it :-(.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
now let&#39;s test to access some java library&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35) &lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import jnius&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from jnius import autoclass&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; Stack = autoclass(&#39;java.util.Stack&#39;)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; stack = Stack()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; stack.push(&#39;hello&#39;)&lt;br /&gt;
&#39;hello&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; stack.push(&#39;world&#39;)&lt;br /&gt;
&#39;world&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; stack.pop()&lt;br /&gt;
&#39;world&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; stack.pop()&lt;br /&gt;
&#39;hello&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; System = autoclass(&#39;java.lang.System&#39;)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; System.out.println(&#39;Hello World&#39;)&lt;br /&gt;
Hello World&lt;/blockquote&gt;
for more learning stuff you can refer to:&lt;br /&gt;
&lt;a href=&quot;http://pyjnius.readthedocs.org/en/latest/&quot;&gt;http://pyjnius.readthedocs.org/en/latest/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://kivy.org/planet/2012/08/pyjnius-accessing-java-classes-from-python/&quot;&gt;http://kivy.org/planet/2012/08/pyjnius-accessing-java-classes-from-python/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
with this project, it&#39;s possible to develop android app using python. To create android package we can use &lt;a href=&quot;http://python-for-android.readthedocs.org/en/latest/&quot;&gt;http://python-for-android.readthedocs.org/en/latest/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/8316551612859140255/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-access-java-through-jnius.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/8316551612859140255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/8316551612859140255'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-access-java-through-jnius.html' title='Python Access Java Through JNIus'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimEAfkUoqmsxD49k0K5Db3L8qcp5eNM9PqdCOsimE7fWpd8RdBJBvOyDqZJcjOBzaR1F7UX2o08WLOSdzHv6o6ZIzB-KVbBhU_QYfqDjBtwQXzRI5oiDl-eeSqHJ-mMdVx6WTWfaygYRc/s72-c/python-mobile.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-2539280666744787928</id><published>2015-10-25T05:44:00.001-07:00</published><updated>2015-11-24T17:50:08.597-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><title type='text'>How to make android emulator run faster?</title><content type='html'>Android emulator running&amp;nbsp;too slow? this is main problem when develop android application :-). I always trying to find other solution rather&amp;nbsp;than using original google android emulator.&lt;br /&gt;
&lt;br /&gt;
After do some googling and learn little about virtualization technology, I got little knowledge how to run android emulator using intel virtualization technology (VT) this feature must be activated through BIOS.&lt;br /&gt;
&lt;br /&gt;
We need to access bios and activate intel virtualization technology, keep in mind that not all processor and motherboard support intel virtualization technology. But if intel virtualization technology exist in your bios setting you can use it to run android emulator using x86 image.&lt;br /&gt;
&lt;br /&gt;
If your processor and motherboard support intel virtualization technology install &lt;b&gt;haxm&lt;/b&gt; through android sdk manager&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiISSkAMiNovDZNCnFiqXyXyNfmFzDwYuo_wAkpOoTgKnbebAM5Fm_BMw6b6TwLgqKR5S0RNJJdtmYB_o5mBRgbMlhHOlRvCD1ZH1MVQpg9uKL3bMzNp1_RCncdwb3E1UANJs1Vkr2hR0Y/s1600/install_haxm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;85&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiISSkAMiNovDZNCnFiqXyXyNfmFzDwYuo_wAkpOoTgKnbebAM5Fm_BMw6b6TwLgqKR5S0RNJJdtmYB_o5mBRgbMlhHOlRvCD1ZH1MVQpg9uKL3bMzNp1_RCncdwb3E1UANJs1Vkr2hR0Y/s400/install_haxm.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span id=&quot;goog_4720043&quot;&gt;&lt;span id=&quot;goog_1009371616&quot;&gt;But if your computer doesn&#39;t support inter haxm don&#39;t worry just skip haxm installation step&lt;/span&gt;,&lt;/span&gt;&lt;/b&gt;&lt;span id=&quot;goog_4720043&quot;&gt; then go to android sdk installation folder and goto &lt;b&gt;extra/intel/Hardware_Accelerated_Execution_Manager&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span id=&quot;goog_4720043&quot;&gt; &lt;/span&gt;&lt;/b&gt;&lt;span id=&quot;goog_4720043&quot;&gt;then install using silent_install.bat must be using command prompt with administrator mode&lt;/span&gt;&lt;b&gt;&lt;span id=&quot;goog_4720043&quot;&gt;:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
D:\SDK\android-sdk-windows\extras\intel\Hardware_Accelerated_Execution_Manager&amp;gt;silent_install.bat -m 512&lt;/blockquote&gt;
-m parameter is memory will be used by haxm manager, don&#39;t use memory more than 1024MB, after installation succes you will get message in command prompt will return success message.&lt;br /&gt;
&lt;br /&gt;
Next step install image x86 both, x86 image system and x86 google api image system.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsEMASZLN7TDJUBLxbPyZeYPWpZH1IXgWcSlGxNrQB69IUHqsok4BR9Ghqy_7XQQnsD5uRNdQv-xUqPTqXMQNNSY-UuOTHL1Y4EMSwGw9Tm2hGAVHWamHdxPhgNQJN0uPsMjZ_IcBSs-E/s1600/install_x86.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;96&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsEMASZLN7TDJUBLxbPyZeYPWpZH1IXgWcSlGxNrQB69IUHqsok4BR9Ghqy_7XQQnsD5uRNdQv-xUqPTqXMQNNSY-UuOTHL1Y4EMSwGw9Tm2hGAVHWamHdxPhgNQJN0uPsMjZ_IcBSs-E/s400/install_x86.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Then setup your android virtual device (AVD), setup using one of x86 image system, don&#39;t forget to Use GPU Host&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWeuE4EaCve8Z89wCTnir2998ko9EOK7xzSj_RVjOiS2O723NRJD2zF-a6uPrs_hoXGljS3-jaT8yLJxqQVSlVzry9fo-obiheQ-fVvgvGInwQFRBVEEKmmpyle9BmiWY4JiyLXwN4-4w/s1600/avd.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;233&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWeuE4EaCve8Z89wCTnir2998ko9EOK7xzSj_RVjOiS2O723NRJD2zF-a6uPrs_hoXGljS3-jaT8yLJxqQVSlVzry9fo-obiheQ-fVvgvGInwQFRBVEEKmmpyle9BmiWY4JiyLXwN4-4w/s400/avd.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
That&#39;s it, and let you got fast android emulation.</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/2539280666744787928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/how-to-make-android-emulator-run-faster.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/2539280666744787928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/2539280666744787928'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/how-to-make-android-emulator-run-faster.html' title='How to make android emulator run faster?'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiISSkAMiNovDZNCnFiqXyXyNfmFzDwYuo_wAkpOoTgKnbebAM5Fm_BMw6b6TwLgqKR5S0RNJJdtmYB_o5mBRgbMlhHOlRvCD1ZH1MVQpg9uKL3bMzNp1_RCncdwb3E1UANJs1Vkr2hR0Y/s72-c/install_haxm.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-5333982053379553943</id><published>2015-10-20T23:42:00.003-07:00</published><updated>2015-11-24T17:50:41.175-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="oauth"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python LinkedIn REST API Implementation</title><content type='html'>LinkedIn using OAuth Version 2.0 it&#39;s different process compare with 
OAuth Version 1.0. Newer version is more easy to implement we don&#39;t 
really need to create parameter with oauth_ prefix and generate 
signature on client side, for more information about oauth version 2.0 
we can refer to official oauth page &lt;a href=&quot;http://oauth.net/2/&quot;&gt;http://oauth.net/2/&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
All
 request should use https protocol and redirect url must be accessible 
if not we can&#39;t get code for generate access token. The step is simple 
just 2 step only.&lt;br /&gt;
&lt;br /&gt;
1. Generate grant access url, from here we will redirected to our redirect url and we will get code for authorization code&lt;br /&gt;
2. Generate access token using that code with POST method and we will get token access with specific time expired&lt;br /&gt;
&lt;br /&gt;
We
 can use that token access to call API to provider. Token access will 
expired in specified time and we need to renew access token with both 
step.&lt;br /&gt;
&lt;br /&gt;
You can grab pyLinkedinAPI from my github repository &lt;a href=&quot;https://github.com/amru-rosyada/pyLinkedinAPI&quot;&gt;https://github.com/amru-rosyada/pyLinkedinAPI&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Please
 if you use it, don&#39;t forget to give us feedback. Next project I will 
try to implement Facebook, G+, Instagram and Flickr as far as I have 
little time to make it :D </content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/5333982053379553943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-linkedin-rest-api-implementation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/5333982053379553943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/5333982053379553943'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-linkedin-rest-api-implementation.html' title='Python LinkedIn REST API Implementation'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-7238927625723053959</id><published>2015-10-20T23:41:00.003-07:00</published><updated>2015-11-24T17:50:58.668-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="oauth"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python Tumblr REST API Implementation</title><content type='html'>In previous post I was implement python twitter API, today I will talk something about tumblr API implementation.&lt;br /&gt;
&lt;br /&gt;
I
 guess twitter, tumblr, linkedin and yahoo used same oauth method and 
api implementation. I use pyTwitterAPI base code to implement tumblr 
rest API and still work but with little additional parameter.&lt;br /&gt;
&lt;br /&gt;
Tumblr
 is yahoo like API implementation as we know tumblr was acquired by 
yahoo :-) so if it&#39;s worked with tumblr, it&#39;s also will work with yahoo 
API :D&lt;br /&gt;
&lt;br /&gt;
The main different with twitter API call is 
tumblr add api_key parameter which is consumer key. So if I want to call
 tumblr rest API, I must pass api_key=MY_CONSUMER_KEY in api url.&lt;br /&gt;
&lt;br /&gt;
ex:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;a href=&quot;http://api.tumblr.com/v2/blog/scipsy.tumblr.com/info?api_key=fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4&quot;&gt;http://api.tumblr.com/v2/blog/scipsy.tumblr.com/info?api_key=fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4&lt;/a&gt;&lt;/blockquote&gt;
&lt;br /&gt;
Most
 of tumblr api call need base hostname as parameter. For example my 
tumblr domain is http://xyzmind.tumblr.com, so I need to call it with 
http://api.tumblr.com/v2/blog/xyzmind.blogspot.com/info?api_key=fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4.
 It&#39;s also work with tumblr custom domain :D&lt;br /&gt;
&lt;br /&gt;
You can grab my python tumblr API implementation from my github repository &lt;a href=&quot;https://github.com/amru-rosyada/pyTumblrAPI&quot;&gt;https://github.com/amru-rosyada/pyTumblrAPI&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Let me know if something wrong, may you want to contribute with my project.</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/7238927625723053959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-tumblr-rest-api-implementation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/7238927625723053959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/7238927625723053959'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-tumblr-rest-api-implementation.html' title='Python Tumblr REST API Implementation'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-5644259170268831301</id><published>2015-10-20T23:40:00.003-07:00</published><updated>2015-11-24T17:51:09.941-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="oauth"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python Twitter REST API Implementation</title><content type='html'>Before read this article maybe you need to read my previous article 
http://walkinsmile.blogspot.com/2015/04/python-oauth-implementation-its-not.html&lt;br /&gt;
&lt;br /&gt;
I
 already wrote some codes in a day to implement wrapper for twitter REST
 API (OAuth V1.0 and REST API V1.1), this code will simplify process to 
call twitter REST API from python code.&lt;br /&gt;
&lt;br /&gt;
It&#39;s not that 
complex and not that hard and just little code to help other developer 
if they need to simplify twitter REST API call.&lt;br /&gt;
&lt;br /&gt;
I use 
python version 3.4 :-), you may need some modifications and tuning to 
run this code on older python, especially older than version 3.&lt;br /&gt;
&lt;br /&gt;
You can grab my code on my github repository free to use, modify and redistribute &lt;a href=&quot;https://github.com/amru-rosyada/pyTwitterAPI&quot;&gt;https://github.com/amru-rosyada/pyTwitterAPI &lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/5644259170268831301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-twitter-rest-api-implementation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/5644259170268831301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/5644259170268831301'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-twitter-rest-api-implementation.html' title='Python Twitter REST API Implementation'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-8649725811535892722</id><published>2015-10-20T23:39:00.003-07:00</published><updated>2015-11-24T17:56:01.827-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="tutorial"/><title type='text'>Understanding python decorator in easy way</title><content type='html'>I still have enough energy to write something on my blog :D after one
 week trip to Jakarta for some work reason. I am so tired but I want to 
write and share something about python decorator before I sleep :-).&lt;br /&gt;
&lt;br /&gt;
Lets see how python function work,&lt;br /&gt;
&lt;br /&gt;
Code 1:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
def myfunc(a):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print(a)&lt;br /&gt;
&lt;br /&gt;
decorator = myfunc&lt;br /&gt;
decorator(&#39;It\&#39;s Works&#39;)&lt;/blockquote&gt;
Output 1:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
It&#39;s Works&lt;/blockquote&gt;
&lt;br /&gt;
Code 2:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
def myfunc(*args):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; print(args)&lt;br /&gt;
&lt;br /&gt;
decorator = myfunc&lt;br /&gt;
decorator(&#39;It\&#39;s&#39;, &#39;Works&#39;, &#39;Yeah&#39;, &#39;Must be ok&#39;)&lt;/blockquote&gt;
Output 2:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
(&quot;It&#39;s&quot;, &#39;Works&#39;, &#39;Yeah&#39;, &#39;Must be ok&#39;)&lt;/blockquote&gt;
&lt;br /&gt;
Code 3:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
def myfunc(**kwargs):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(kwargs)&lt;br /&gt;
&lt;br /&gt;
decorator = myfunc&lt;br /&gt;
decorator(a=1, b=2, c=3)&lt;/blockquote&gt;
Output 3:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
{&#39;a&#39;:1, &#39;b&#39;:2, &#39;c&#39;:3} &lt;/blockquote&gt;
&lt;br /&gt;
Inner Function&lt;br /&gt;
Inner function is function inside function or we can call it nested function. Look at code bellow:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
def myfunc(a):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def inner_myfunc():&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(a)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return a&lt;br /&gt;
&lt;br /&gt;
decorator = myfunc&lt;br /&gt;
decorator(&#39;inner myfunc&#39;)&lt;/blockquote&gt;
Output should be:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&#39;inner myfunc&#39;&lt;/blockquote&gt;
from the code we can se that, argument or parameter a is accessible from inner function.&lt;br /&gt;
&lt;br /&gt;
I have some question why I always wrote &lt;b&gt;decorator = myfunc&lt;/b&gt;? I just want to show python function can be assigned to var as alias or pointer.&lt;br /&gt;
&lt;br /&gt;
@some_decorator&lt;br /&gt;
def myfunc():&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return a&lt;br /&gt;
&lt;br /&gt;
it&#39;s mean:&lt;br /&gt;
myfunc = some_decorator(myfunc)&lt;br /&gt;
&lt;br /&gt;
Lets try to the real code with decorator implementation:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;br /&gt;
# define logger function&lt;br /&gt;
# we will this for as decorator&lt;br /&gt;
def logger(func):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def inner(*args, **kwargs): #1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;Arguments were: %s, %s&quot; % (args, kwargs)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return func(*args, **kwargs) #2&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return inner&lt;br /&gt;
&lt;br /&gt;
# use the decorator &lt;br /&gt;
@logger&lt;br /&gt;
def myfunc1(x, y=1):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return x * y&lt;br /&gt;
&lt;br /&gt;
# use the decorator &lt;br /&gt;
@logger&lt;br /&gt;
def myfunc2():&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2&lt;/blockquote&gt;
&lt;br /&gt;
After define function now try to call myfunc1 and myfunc2:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
# call function &lt;br /&gt;
myfunc1(5, 4)&lt;br /&gt;
&lt;br /&gt;
# output should be &lt;br /&gt;
Arguments were: (5, 4), {}&lt;br /&gt;
20&lt;br /&gt;
&lt;br /&gt;
# call function &lt;br /&gt;
myfunc1(1)&lt;br /&gt;
&lt;br /&gt;
# output should be &lt;br /&gt;
Arguments were: (1,), {}&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
# call function &lt;br /&gt;
myfunc2()&lt;br /&gt;
&lt;br /&gt;
# output should be &lt;br /&gt;
Arguments were: (), {}&lt;br /&gt;
2 &lt;/blockquote&gt;
&lt;br /&gt;
If you need more explanation you can comment this post, just comment and I will try to answer :-).&lt;br /&gt;
&lt;br /&gt;
Let Sleep.....</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/8649725811535892722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/understanding-python-decorator-in-easy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/8649725811535892722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/8649725811535892722'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/understanding-python-decorator-in-easy.html' title='Understanding python decorator in easy way'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-2483853654065860391</id><published>2015-10-20T23:38:00.005-07:00</published><updated>2015-11-24T17:51:38.153-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="oauth"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python OAuth implementation it&#39;s not that hard!</title><content type='html'>Did you know about OAuth ? I will explain about OAuth from some resources,&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Wikipedia: &lt;/b&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/OAuth&quot;&gt;http://en.wikipedia.org/wiki/OAuth&lt;/a&gt;&lt;br /&gt;
OAuth
 is an open standard for authorization. OAuth provides client 
applications a &#39;secure delegated access&#39; to server resources on behalf 
of a resource owner. It specifies a process for resource owners to 
authorize third-party access to their server resources without sharing 
their credentials. Designed specifically to work with Hypertext Transfer
 Protocol (HTTP), OAuth essentially allows access tokens to be issued to
 third-party clients by an authorization server, with the approval of 
the resource owner, or end-user. The client then uses the access token 
to access the protected resources hosted by the resource server. OAuth 
is commonly used as a way for web surfers to log into third party web 
sites using their Microsoft, Google, Facebook or Twitter accounts, 
without worrying about their access credentials being compromised.&lt;br /&gt;
&lt;br /&gt;
If you want to know more about OAuth standard you can refer to &lt;a href=&quot;http://oauth.net/&quot;&gt;http://oauth.net/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In this post I will use &lt;a href=&quot;http://python.org/&quot;&gt;Python version 3.4&lt;/a&gt;,&lt;br /&gt;
&lt;br /&gt;
Something you need to know about OAouth implementation:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Know about REST API from service provider like twitter, facebook, 
google, tumblr, yahoo etc. They have different method when request using
 oauth. some provider using POST only or GET only or both.&lt;/li&gt;
&lt;li&gt;Know about OAuth standard at least you have read it&lt;/li&gt;
&lt;li&gt;Know about term which is used by OAuth like oauth_callback, 
oauth_nonce, oauth_consumer_key, oauth_consumer_secret, oauth_token, 
oauth_token_secret, oauth_timestamp, oauth_signature, 
oauth_signature_method and oauth_version&lt;/li&gt;
&lt;li&gt;that&#39;s it&lt;/li&gt;
&lt;/ol&gt;
OAuth using CONSUMER_KEY and CONSUMER_SECRET to generate token, then this token will be use to access API from service provider.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;I will use &lt;a href=&quot;https://apps.twitter.com/&quot;&gt;twitter rest api&lt;/a&gt;
 for this implementation, but this will be useable for common OAuth 
standard :-) don&#39;t worry. Before we start you must create application on
 twitter follow this &lt;a href=&quot;https://apps.twitter.com/&quot;&gt;twitter app registration&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
1. If you already have account you can sign in, but if you don&#39;t have you need register to twitter&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRCarKx4fAMB1-6lFrrjLy5gM1QFw9YHmazo-1YFjdFr5Gbhprfx2bZ-51MAoGQaQKfLyGPhMjABjeRKwoxoLSrk-1C8uv2_77lx84sjO1-O3zrZGuloyzXk_mC3D0CguYFrOV1-OSQUE/s1600/1.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;211&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRCarKx4fAMB1-6lFrrjLy5gM1QFw9YHmazo-1YFjdFr5Gbhprfx2bZ-51MAoGQaQKfLyGPhMjABjeRKwoxoLSrk-1C8uv2_77lx84sjO1-O3zrZGuloyzXk_mC3D0CguYFrOV1-OSQUE/s1600/1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt; &lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
2. After sign in, you will get create application button if you don&#39;t have any application. Then just create new app&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPBW5yAWThocUyemHQRBA_f5DuepuFKkRdNVIOSjXeXyO-iWCxksfUvQAEcMYDbUumo-JbXDQNtnUmR2PuzaEWi5nefwYqcgDpCuZA-3IvjpVngVBz0ZV_erogc1QKxfxy0FsHL5-Wvfg/s1600/2.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;170&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPBW5yAWThocUyemHQRBA_f5DuepuFKkRdNVIOSjXeXyO-iWCxksfUvQAEcMYDbUumo-JbXDQNtnUmR2PuzaEWi5nefwYqcgDpCuZA-3IvjpVngVBz0ZV_erogc1QKxfxy0FsHL5-Wvfg/s1600/2.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
3.
 Fill your application name, description, website and callback. Callback
 for what? callback is url that will call after user success and granted
 your application. For now we don&#39;t really care about this we just want 
to create oauth impletentation to get token and token secret&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFkog_FDIFlFSwajqY1t_G3g3KAPyn4Oo3gttpOuPdx8AP_sTWTv9XriyBpcOokNVZ_3zPhVo1DdZFqPoprJe7DnTvrbzSvu1hA5HZEVgYzAmZ7gpxXt3QlejfrchO-5A34pQtdBHfhVw/s1600/3.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;210&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFkog_FDIFlFSwajqY1t_G3g3KAPyn4Oo3gttpOuPdx8AP_sTWTv9XriyBpcOokNVZ_3zPhVo1DdZFqPoprJe7DnTvrbzSvu1hA5HZEVgYzAmZ7gpxXt3QlejfrchO-5A34pQtdBHfhVw/s1600/3.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
4.
 After finish your app creation, then scooll down on your app detail. 
You will get some information about url for request token, 
authorization, access token.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4OkByamW1vscJlXolMg1PIZiDdK49t5XaCh3v4uQRT40IJ2eO4hmYA4XkhIdaHdHlkViRbZNNW3D5RyBUuPR2K4N9km6ib1OBePZYVf62mATVY7XZypmxxIqZ0hsNv4_egbwLBSoUbU4/s1600/4.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;228&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4OkByamW1vscJlXolMg1PIZiDdK49t5XaCh3v4uQRT40IJ2eO4hmYA4XkhIdaHdHlkViRbZNNW3D5RyBUuPR2K4N9km6ib1OBePZYVf62mATVY7XZypmxxIqZ0hsNv4_egbwLBSoUbU4/s1600/4.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
5. Go to tab &lt;b&gt;Keys and Access Tokens&lt;/b&gt;
 and The important thing is you need to retrieve CONSUMER_KEY and 
CONSUMER_SECRET from your app. Sorry I don&#39;t want show my consumer 
secret :D.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4NbNhiTgg-DbW_OilBAFFCYKQoblL93W-iQQSkQCtF65WQKrERE5C5Q-_SccxyEFcOpU0FttN5MWXw-3S1-tQ6ufauBi4aOzVmEE5RrOyTI5rBv6cRFLIqCDDb0ZzjgKdJqduv5cx0y0/s1600/5.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;165&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4NbNhiTgg-DbW_OilBAFFCYKQoblL93W-iQQSkQCtF65WQKrERE5C5Q-_SccxyEFcOpU0FttN5MWXw-3S1-tQ6ufauBi4aOzVmEE5RrOyTI5rBv6cRFLIqCDDb0ZzjgKdJqduv5cx0y0/s1600/5.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Ok then lets we start, create implementation of OAuth is not hard the only we need is follow the rule.&lt;br /&gt;
I
 already create basic code, using twitter api for testing my code 
implementation you can grab it from my github repository here &lt;a href=&quot;https://github.com/amru-rosyada/pyTwitterAPI&quot;&gt;https://github.com/amru-rosyada/pyTwitterAPI&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Thats
 the basic code, but I will add more for retrieve or post status. The 
basic is enough if you want to implement other request. follow this &lt;a href=&quot;https://dev.twitter.com/rest/public&quot;&gt;twitter rest api&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Regards, </content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/2483853654065860391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-oauth-implementation-its-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/2483853654065860391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/2483853654065860391'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-oauth-implementation-its-not.html' title='Python OAuth implementation it&#39;s not that hard!'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRCarKx4fAMB1-6lFrrjLy5gM1QFw9YHmazo-1YFjdFr5Gbhprfx2bZ-51MAoGQaQKfLyGPhMjABjeRKwoxoLSrk-1C8uv2_77lx84sjO1-O3zrZGuloyzXk_mC3D0CguYFrOV1-OSQUE/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-6142499553008975783</id><published>2015-10-20T23:38:00.001-07:00</published><updated>2015-11-24T17:51:50.736-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>How to request POST and GET using Python ?</title><content type='html'>I want to share about HTTP request using python, HTTP request can be 
done using POST or GET method. The main different between POST and GET 
is on HTTP header, POST method need &lt;b&gt;Content-Type: application/x-www-form-urlencoded&lt;/b&gt; definition when sending data.&lt;br /&gt;
&lt;br /&gt;
If you want to know about HTTP header you can refer to wiki page &lt;a href=&quot;http://en.wikipedia.org/wiki/List_of_HTTP_header_fields&quot;&gt;http://en.wikipedia.org/wiki/List_of_HTTP_header_fields&lt;/a&gt; or W3 page &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html&quot;&gt;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
But
 I will not talk about HTTP Protocol standard in this post, I only will 
share about how to request POST and GET using python (I use python 
version 3.4).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;POST Method:&lt;/b&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
# import url Request to create request object &lt;br /&gt;
from urllib.request import Request&lt;br /&gt;
&lt;br /&gt;
# import urlopen to send request to web site &lt;br /&gt;
from urllib.request import urlopen&lt;br /&gt;
&lt;br /&gt;
# for post request need define Content-Type : application/x-www-form-urlencoded on http header&lt;br /&gt;
header = {&#39;Content-Type&#39;:&#39;application/x-www-form-urlencoded&#39;}&lt;br /&gt;
&lt;br /&gt;
# create request object&lt;br /&gt;
# data query need to encode to byte, it is save to use standart ISO-8859-1 &lt;br /&gt;
req = Request(&#39;http://localhost:8888/p/authenticate/google&#39;, &#39;firstname=amru&amp;amp;lastname=rosyada&#39;.encode(&#39;ISO-8859-1&#39;), header)&lt;br /&gt;
&lt;br /&gt;
# send post request&lt;br /&gt;
post_response = urlopen(req)&lt;/blockquote&gt;
&lt;br /&gt;
&lt;b&gt;GET Method:&lt;/b&gt;&lt;br /&gt;
GET
 code snippet is same with POST but without 
application/x-www-form-urlencoded on http header data parameter should 
be None of left it blank.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
# import url Request to create request object &lt;br /&gt;
from urllib.request import Request&lt;br /&gt;
&lt;br /&gt;
# import urlopen to send request to web site &lt;br /&gt;
from urllib.request import urlopen&lt;br /&gt;
&lt;br /&gt;
# create request object&lt;br /&gt;
# data query need to encode to byte, it is save to use standart ISO-8859-1 &lt;br /&gt;
req = Request(&#39;http://localhost:8888/p/authenticate/google?firstname=amru&amp;amp;lastname=rosyada&#39;, None)&lt;br /&gt;
&lt;br /&gt;
# send post request&lt;br /&gt;
get_response = urlopen(req)&lt;/blockquote&gt;
Thanks :D </content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/6142499553008975783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/how-to-request-post-and-get-using-python.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/6142499553008975783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/6142499553008975783'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/how-to-request-post-and-get-using-python.html' title='How to request POST and GET using Python ?'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-3201341535585712035</id><published>2015-10-20T23:37:00.002-07:00</published><updated>2015-11-24T17:56:28.127-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="tutorial"/><title type='text'>Python in a Minute</title><content type='html'>Today I will share about how to learn python in a minute, in this post I will use &lt;a href=&quot;http://python.org/&quot;&gt;python version 3&lt;/a&gt; only and discuss about &lt;b&gt;python keyword, using python module, python mode, basic syntax, operator, function, python data type and class&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
This post is not deep concept, but about basic concept before we start deep learning into python.&lt;br /&gt;
&lt;br /&gt;
Python
 is easy programming language to learn, powerful programming language. 
It has efficient high-level data structures and a simple but effective 
approach to object-oriented programming. Python’s elegant syntax and 
dynamic typing, together with its interpreted nature, make it an ideal 
language for scripting and rapid application development in many areas 
on most platforms.&lt;br /&gt;
&lt;br /&gt;
Learning python is not hard because 
it&#39;s &quot;human language&quot; :-) it&#39;s mean that python language is more 
readable, portable, clean, easy to develop and easy to extends.&lt;br /&gt;
&lt;br /&gt;
Ok lets start don&#39;t wasting time :D.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Python Mode&lt;/b&gt;&lt;br /&gt;
Python
 have two mode which is interpreter mode and scripting mode, we don&#39;t 
need to compile the code because compilation process to byte code will 
be handled by python interpreter.&lt;br /&gt;
&lt;br /&gt;
You need to install python interpreter before you can start using python, can be downloaded from here &lt;a href=&quot;https://www.python.org/&quot;&gt;python.org&lt;/a&gt;. Choose the right one for you distribution OS.&lt;br /&gt;
&lt;br /&gt;
Interpreter
 mode can be access from terminal emulator in linux and mac or cmd in 
windows. Most linux distro include python interpreter on each their 
distribution.&lt;br /&gt;
&lt;br /&gt;
From terminal emulator or cmd you simply type python you will get in to python interpreter depend on your system.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&amp;nbsp;&lt;/blockquote&gt;
With interpreter method you can use it as calculator like sum, div, mod etc&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 1+1&lt;br /&gt;
2&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 3*3&lt;br /&gt;
9&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 3**4&lt;br /&gt;
81&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; 6%2&lt;br /&gt;
0&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;The second one is script method, you can save python code in &lt;b&gt;.py&lt;/b&gt;
 extension and run it with python interpreter. Let start with hello 
world example :D, open your text editor (notepad, notepad++, sublime 
text, emacs or nano up to you which one do you choose or you prefer 
using other text editor) create &lt;b&gt;helloWorld.py&lt;/b&gt; then save it. Put this line into helloWorld.py and save it.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
a = &#39;Hello World, this is my first python script&#39;&lt;br /&gt;
print(a)&lt;/blockquote&gt;
Open terminal in the same folder where helloWorld.py file saved. Then type &lt;b&gt;python helloWorld.py&lt;/b&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python helloWorld.py&lt;br /&gt;
Hello World, this is my first python script&lt;/blockquote&gt;
Ok, now we know about interpreter mode and scripting mode. :-) super easy isn&#39;t it?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Python Keyword&lt;/b&gt;&lt;br /&gt;
The
 following identifiers are used as reserved words, or keywords of the 
language, and cannot be used as ordinary identifiers. They must be 
spelled exactly as written here:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
False,
 class, finally, is, return, None, continue, for, lambda, try, True, 
def, from, nonlocal, while, and, del, global, not, with, as, elif, if, 
or, yield, assert, else, import, pass, break, except, in, raise&lt;/blockquote&gt;
&lt;b&gt;Basic Syntax&lt;/b&gt;&lt;br /&gt;
Python
 use indentation for block code, I recommended using space rather than 
tab so it can be portable if change to other text editor. Change from 
your text editor setting and change tab to 4 spaces or depend on your 
preference.&lt;br /&gt;
&lt;br /&gt;
Python syntax compare with other language:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;C language:&lt;/b&gt;&lt;br /&gt;
// this is line comment in C&lt;br /&gt;
/*&lt;br /&gt;
* this is block comment in C&lt;br /&gt;
*/&lt;br /&gt;
int add(int a, int b){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return a*b;&lt;br /&gt;
}&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;PHP language:&lt;/b&gt;&lt;br /&gt;
// this is line comment in PHP&lt;br /&gt;
/*&lt;br /&gt;
* this is block comment in PHP&lt;br /&gt;
*/&lt;br /&gt;
function add($a, $b){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return $a*$b;&lt;br /&gt;
}&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;Java language:&lt;/b&gt;&lt;br /&gt;
// this is line comment in Java&lt;br /&gt;
/*&lt;br /&gt;
* this is block comment in Java&lt;br /&gt;
*/&lt;br /&gt;
public int add(int a, int b){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return a*b;&lt;br /&gt;
}&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b&gt;Python language:&lt;/b&gt;&lt;br /&gt;
# this is line comment in C&lt;br /&gt;
&quot;&quot;&quot;&lt;br /&gt;
&amp;nbsp;this is block comment in C&lt;br /&gt;
&quot;&quot;&quot;&lt;br /&gt;
def add(a, b):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return a*b&lt;/blockquote&gt;
Which
 one is simpler? :D. Yes python is simpler and clean. I don&#39;t mean that 
other language is bad but I just want to show to you python is more 
simpler than other.&lt;br /&gt;
&lt;br /&gt;
Keep in mind python using indentation for block code, let try other sample create fibonacci.py, put this code and save it.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
a, b = 0, 1&lt;br /&gt;
while b &amp;lt; 10:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print(b)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; a, b = b, a+b&lt;/blockquote&gt;
then run &lt;b&gt;python fibonacci.py&lt;/b&gt;, the execution output should be&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
1&lt;br /&gt;
1&lt;br /&gt;
2&lt;br /&gt;
3&lt;br /&gt;
5&lt;br /&gt;
8&lt;/blockquote&gt;
&lt;b&gt;Python Operator&lt;/b&gt;&lt;br /&gt;
Like in other programming language python have some operator, this table will explain operator in python&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;1&quot; class=&quot;docutils&quot; style=&quot;border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-collapse: collapse; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #222222; font-family: &#39;Lucida Grande&#39;, Arial, sans-serif; font-size: 16px; margin-bottom: 10px; margin-top: 10px; min-width: 20%;&quot;&gt;&lt;thead valign=&quot;bottom&quot;&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;th class=&quot;head&quot; style=&quot;background-color: #eeeeee; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Operation&lt;/th&gt;&lt;th class=&quot;head&quot; style=&quot;background-color: #eeeeee; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Syntax&lt;/th&gt;&lt;th class=&quot;head&quot; style=&quot;background-color: #eeeeee; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Function&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;&lt;tbody valign=&quot;top&quot;&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Addition&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;add(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Concatenation&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;seq1&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;seq2&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;concat(seq1,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;seq2)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Containment Test&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;obj&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;seq&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;contains(seq,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;obj)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Division&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;/&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;truediv(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Division&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;//&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;floordiv(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Bitwise And&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;&amp;amp;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;and_(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Bitwise Exclusive Or&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;^&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;xor(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Bitwise Inversion&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;~&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;invert(a)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Bitwise Or&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;|&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;or_(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Exponentiation&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;**&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;pow(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Identity&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;is_(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Identity&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;not&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;is_not(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Indexed Assignment&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;obj[k]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;v&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;setitem(obj,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;k,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;v)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Indexed Deletion&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;del&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;obj[k]&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;delitem(obj,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;k)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Indexing&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;obj[k]&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;getitem(obj,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;k)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Left Shift&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;lshift(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Modulo&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;%&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;mod(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Multiplication&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;*&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;mul(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Negation (Arithmetic)&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;-&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;neg(a)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Negation (Logical)&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;not&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;not_(a)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Positive&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;+&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;pos(a)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Right Shift&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;rshift(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Slice Assignment&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;seq[i:j]&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;values&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;setitem(seq,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;slice(i,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;j),&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;values)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Slice Deletion&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;del&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;seq[i:j]&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;delitem(seq,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;slice(i,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;j))&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Slicing&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;seq[i:j]&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;getitem(seq,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;slice(i,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;j))&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;String Formatting&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;s&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;%&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;obj&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;mod(s,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;obj)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Subtraction&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;-&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;sub(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Truth Test&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;obj&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;truth(obj)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Ordering&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;&amp;lt;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;lt(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Ordering&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;&amp;lt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;le(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Equality&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;==&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;eq(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Difference&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;!=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;ne(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-even&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Ordering&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;&amp;gt;=&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;ge(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr class=&quot;row-odd&quot;&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;Ordering&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;a&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;td style=&quot;background-color: white; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221) !important; padding: 0.3em 0.5em;&quot;&gt;&lt;tt class=&quot;docutils literal&quot; style=&quot;background-color: #ecf0f3; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; font-family: monospace, sans-serif; padding: 0px 1px;&quot;&gt;&lt;span class=&quot;pre&quot;&gt;gt(a,&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot;&gt;b)&lt;/span&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div&gt;
Checking syntax is easy, we can use python interpreter mode, ex:&lt;/div&gt;
&lt;div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # for a + b&lt;br /&gt;
... 1 + 2&lt;br /&gt;
3&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # for a - b&lt;br /&gt;
... 1 - 2&lt;br /&gt;
-1&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # concat two string&lt;br /&gt;
... &#39;hello&#39; + &#39; world&#39;&lt;br /&gt;
&#39;hello world&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # shift right operation&lt;br /&gt;
... 1 &amp;gt;&amp;gt; 2&lt;br /&gt;
0&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # shift left operation&lt;br /&gt;
... 1 &amp;lt;&amp;lt; 2&lt;br /&gt;
4&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # test if object in list&lt;br /&gt;
... &#39;a&#39; in [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]&lt;br /&gt;
True&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
&lt;b&gt;Python Data Type&lt;/b&gt;&lt;br /&gt;
Python have powerful built in data type &lt;b&gt;dict&lt;/b&gt;, &lt;b&gt;list&lt;/b&gt;, &lt;b&gt;set&lt;/b&gt;, &lt;b&gt;frozenset and&lt;/b&gt;&amp;nbsp;&lt;b&gt;tuple&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Python Data Type : Dict&lt;br /&gt;
Dict is dictionary data type &amp;nbsp;must contain pair key and value, initialization of dict using {}&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;
 a = {&#39;hello&#39;:&#39;world&#39;, 1:&#39;oke&#39;, &#39;yes&#39;:10, &#39;dict_in_dict&#39;:{}, 
&#39;list_in_dict&#39;:[1, 2, 3, 4], &#39;tuple_in_dict&#39;:(1, 2, 3, 4)}&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.get(&#39;hello&#39;)&lt;br /&gt;
&#39;world&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.get(&#39;tuple_in_dict&#39;)&lt;br /&gt;
(1, 2, 3, 4)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.get(&#39;list_in_dict&#39;)&lt;br /&gt;
[1, 2, 3, 4]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[&#39;hello&#39;] = &#39;guys&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.get(&#39;hello&#39;)&lt;br /&gt;
&#39;guys&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[&#39;add new item&#39;] = &#39;new item added&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.get(&#39;add new item&#39;)&lt;br /&gt;
&#39;new item added&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
As we can see python dictionary can be mixed value with string, object, int and other python objects.&lt;br /&gt;
&lt;br /&gt;
Python Data Type : List&lt;br /&gt;
List
 in python is like array in C or C++ but more powerful, you can mixed 
value inside list not only one data type. List python support append, 
insert, sort and other operation.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = [1, &#39;oke&#39;, 4, 0.3, &#39;yeah&#39;]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[0]&lt;br /&gt;
1&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[2:]&lt;br /&gt;
[4, 0.3, &#39;yeah&#39;]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[2:-1]&lt;br /&gt;
[4, 0.3]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.append(&#39;append to last&#39;)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a&lt;br /&gt;
[1, &#39;oke&#39;, 4, 0.3, &#39;yeah&#39;, &#39;append to last&#39;]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; del a[0]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a&lt;br /&gt;
[&#39;oke&#39;, 4, 0.3, &#39;yeah&#39;, &#39;append to last&#39;]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.pop(2)&lt;br /&gt;
0.3&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a&lt;br /&gt;
[&#39;oke&#39;, 4, &#39;yeah&#39;, &#39;append to last&#39;]&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
list
 initialization using [], list item can be retrieve using list[index]. 
Negative index will search from last list item. List[-1] mean get last 
item, List[0:3] mead get slice of list from index 0 until index 3.&lt;br /&gt;
&lt;br /&gt;
Python Data Type : Tuple&lt;br /&gt;
Tuple
 is like List the difference between both data type is Tuple immutable, 
the value cannot be change. To initialize tuple use ().&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = (1, 2, 3, 4.3, &#39;iya&#39;)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[1]&lt;br /&gt;
2&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[0:3]&lt;br /&gt;
(1, 2, 3)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[0] = 2&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
&amp;nbsp; File &quot;&amp;lt;stdin&amp;gt;&quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
TypeError: &#39;tuple&#39; object does not support item assignment&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
See last command a[0] = 2 will raise error, because tuple is immutable&lt;br /&gt;
&lt;br /&gt;
Python Data Type : Set, Frozenset&lt;br /&gt;
A
 set object is an unordered collection of distinct hashable objects. 
Common uses include membership testing, removing duplicates from a 
sequence, and computing mathematical operations such as intersection, 
union, difference, and symmetric difference.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = set([1, 2, 3, 4, 5])&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; b = set((3, 4))&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.union(b)&lt;br /&gt;
{1, 2, 3, 4, 5}&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a.difference(b)&lt;br /&gt;
{1, 2, 5}&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; b.issubset(a)&lt;br /&gt;
True&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
As we can see when create set parameter should be iterable object like tuple or list.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Python Loop&lt;/b&gt;&lt;br /&gt;
Python only have two type of loop which is &lt;b&gt;for&lt;/b&gt; and &lt;b&gt;while&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Python Loop : For&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; for i in [1, 2, 3]:&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; print(i)&lt;br /&gt;
...&lt;br /&gt;
1&lt;br /&gt;
2&lt;br /&gt;
3&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; for i in range(3, 10):&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; print(i)&lt;br /&gt;
...&lt;br /&gt;
3&lt;br /&gt;
4&lt;br /&gt;
5&lt;br /&gt;
6&lt;br /&gt;
7&lt;br /&gt;
8&lt;br /&gt;
9&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; for i in (1, 2, 3):&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; print(i)&lt;br /&gt;
...&lt;br /&gt;
1&lt;br /&gt;
2&lt;br /&gt;
3&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; d = {&#39;mami&#39;:&#39;halo&#39;, &#39;papi&#39;:&#39;halo&#39;}&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; for i in d:&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; print(d.get(i))&lt;br /&gt;
...&lt;br /&gt;
halo&lt;br /&gt;
halo&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
Python Loop : While&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = 10&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = 3&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; while a &amp;gt; 0:&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; a -= 1&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; print(a)&lt;br /&gt;
...&lt;br /&gt;
2&lt;br /&gt;
1&lt;br /&gt;
0&lt;/blockquote&gt;
&lt;b&gt;Python Import Module&lt;/b&gt;&lt;br /&gt;
We can import external module or internal python module using import keyword.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import datetime&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from datetime import date&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; date.today()&lt;br /&gt;
datetime.date(2015, 4, 15)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; datetime.datetime.today()&lt;br /&gt;
datetime.datetime(2015, 4, 15, 12, 36, 27, 307647)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
Let create external simple module, create &lt;b&gt;testModule.py&lt;/b&gt; then put this code.&lt;br /&gt;
&lt;blockquote&gt;
def sum_it(a, b):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print(a+b)&lt;br /&gt;
def pow_it(a, b):&lt;br /&gt;
&amp;nbsp; &amp;nbsp; print(a**b)&lt;/blockquote&gt;
Open python interpreter in folder contain testModule.py file then do this stuff.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; from testModule import *&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; sum_it(1, 3)&lt;br /&gt;
4&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; pow_it(2, 5)&lt;br /&gt;
32&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
&amp;nbsp;Finally we can call function from other file.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Python Function&lt;/b&gt;&lt;br /&gt;
To define python function we use &lt;b&gt;def&lt;/b&gt;
 keyword, python function can have default parameter to prevent ordering
 fault. Better if your function have default parameter :D&lt;br /&gt;
Let we do little stuff with python function.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
amrus-MacBook-Pro:Desktop amru$ python&lt;br /&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # let we define functin here&lt;br /&gt;
... def devide_it(a, b):&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; return a/b # return result a devide by b&lt;br /&gt;
...&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # let we call the function&lt;br /&gt;
... devide_it(10, 3)&lt;br /&gt;
3.3333333333333335&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # let try create function and use default parameter&lt;br /&gt;
... def set_name(first_name=&#39;amru&#39;, last_name=&#39;rosyada&#39;):&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; print(first_name + &#39; &#39; + last_name)&lt;br /&gt;
...&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # let call function without parameter&lt;br /&gt;
... set_name()&lt;br /&gt;
amru rosyada&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # let call function with parameter&lt;br /&gt;
... set_name(&#39;David&#39;, &#39;Beckham&#39;)&lt;br /&gt;
David Beckham&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/blockquote&gt;
&lt;b&gt;Python Class&lt;/b&gt;&lt;br /&gt;
As
 high level language python also support OOP Concept(Object Oriented 
Programming). If you don&#39;t know about OOP you must learn it from other 
source.&lt;br /&gt;
Ok let we take a look to python class,&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
Python 3.4.3 (default, Mar 10 2015, 14:53:35)&lt;br /&gt;
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin&lt;br /&gt;
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # let we define a class&lt;br /&gt;
... class ParenClass():&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; def __init__(self): # this is constructor of the class&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.public_paren_var = &#39;a&#39;&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.__private_paren_var = &#39;private a&#39;&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; def public_method(self):&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(&#39;public method&#39;)&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; def __private_method(self):&lt;br /&gt;
... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(&#39;private method&#39;)&lt;br /&gt;
...&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; p = ParenClass()&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # let retrieve public variable&lt;br /&gt;
... p.public_paren_var&lt;br /&gt;
&#39;a&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # we cannot retrieve private variable of class&lt;br /&gt;
... # private variable or method use prefix &#39;__&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; p.__private_paren_var&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
&amp;nbsp; File &quot;&amp;lt;stdin&amp;gt;&quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
AttributeError: &#39;ParenClass&#39; object has no attribute &#39;__private_paren_var&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # let we call public method&lt;br /&gt;
... p.public_method()&lt;br /&gt;
public method&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; # we can&#39;t call private method&lt;br /&gt;
... # private method/function use prefix &#39;__&#39;&lt;br /&gt;
... p.private_method()&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
&amp;nbsp; File &quot;&amp;lt;stdin&amp;gt;&quot;, line 3, in &amp;lt;module&amp;gt;&lt;br /&gt;
AttributeError: &#39;ParenClass&#39; object has no attribute &#39;private_method&#39;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; &lt;/blockquote&gt;
Ok,
 that is the basic of python and now we can learn more deep about python
 concept. Let me know if you need some assist contact me for free.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;br /&gt;&lt;/blockquote&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/3201341535585712035/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-in-minute.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/3201341535585712035'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/3201341535585712035'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/python-in-minute.html' title='Python in a Minute'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-6157091648829233224</id><published>2015-10-20T23:36:00.003-07:00</published><updated>2015-11-24T17:52:19.303-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Setup Python on windows platform</title><content type='html'>Hello guys, today I will share how to setup and install python on 
windows platform. Before installation process you need to download 
python installer for windows platform at &lt;a href=&quot;https://www.python.org/downloads/windows/&quot;&gt;https://www.python.org/downloads/windows/&lt;/a&gt; I recommended to download python 3 latest version.&lt;br /&gt;
&lt;br /&gt;
If you already finished download, run installer by double click your python installer and follow the wizzard :-).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzTSk96eSWg70Cgp2rBuH2Z0RIJ2OS7c3G7y7CtTaZXpcJAms2fkIkj5r5qR99uSjOoj5dYQVu3OL9ganWht4eUggNSpXt6xdnSQKicDGgwvvi4MSZVvqMTX3Eu-hk1AvxE1PSK8KnTpE/s1600/inst1.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;345&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzTSk96eSWg70Cgp2rBuH2Z0RIJ2OS7c3G7y7CtTaZXpcJAms2fkIkj5r5qR99uSjOoj5dYQVu3OL9ganWht4eUggNSpXt6xdnSQKicDGgwvvi4MSZVvqMTX3Eu-hk1AvxE1PSK8KnTpE/s1600/inst1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Until you found this page, don&#39;t forget select &lt;b&gt;Add python.exe to Path&lt;/b&gt;&amp;nbsp; you need this to enable and insert python path on Windows Environment.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDHAo1u7IEwrBcp-g7C6QkcubzvPQAbRGWDG1i-j8j7-tHkT29EhRb4g64uYzTMK-hPqlaswFrNVjOzmweGnkKc3OZHfOFTMbYN0NDnMhKg9Om9NOaEskd_CUb28dPYmmmjrvdLbeUvQc/s1600/inst2.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;292&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDHAo1u7IEwrBcp-g7C6QkcubzvPQAbRGWDG1i-j8j7-tHkT29EhRb4g64uYzTMK-hPqlaswFrNVjOzmweGnkKc3OZHfOFTMbYN0NDnMhKg9Om9NOaEskd_CUb28dPYmmmjrvdLbeUvQc/s1600/inst2.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
After
 installation process finish then we need to check python from command 
prompt but you need to logout and re-login to your windows system.&lt;br /&gt;
&lt;br /&gt;
Open cmd and type &lt;b&gt;python&lt;/b&gt;, you should got this python interpreter.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXF-RPGVDc4iuW-0HrXdiRgsu0-qc8uTGiTl2mzWAdz37G8pJ4Wa-0HD4X2oQT2-M9_BvWeKcaByV7sOk7fmUKD6no0Bs9Z04dg7mlxCDncP1mx3jPOA4Le8RZYTfaozUXN1mKqOfH5T0/s1600/inst3.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;106&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXF-RPGVDc4iuW-0HrXdiRgsu0-qc8uTGiTl2mzWAdz37G8pJ4Wa-0HD4X2oQT2-M9_BvWeKcaByV7sOk7fmUKD6no0Bs9Z04dg7mlxCDncP1mx3jPOA4Le8RZYTfaozUXN1mKqOfH5T0/s1600/inst3.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Type &lt;b&gt;pip&lt;/b&gt; to check python package installer&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9m9gpaNpzL4Aoj-YOFts-DdCn-aya1NE0kO3rUyLI8f7oTzYdMzWsST-gAKbbnUNg0b0dIr1bMnEIKUaQcZYWA3NBfxvFqnnrQtNu7eh5r5H_w9CFkK78UgrNwarC9cY2Dj97XSU56DY/s1600/inst4.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;112&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9m9gpaNpzL4Aoj-YOFts-DdCn-aya1NE0kO3rUyLI8f7oTzYdMzWsST-gAKbbnUNg0b0dIr1bMnEIKUaQcZYWA3NBfxvFqnnrQtNu7eh5r5H_w9CFkK78UgrNwarC9cY2Dj97XSU56DY/s1600/inst4.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Type &lt;b&gt;easy_install --help&lt;/b&gt; to check other package installer method&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDJMI8PP0V3va9NAyTEbRoP0YUw3z1fWGUU0584XqlBUpbB8jrO4PSaMY1FbGxbhL7akwyE-GZXE3gw5yzTTa04B4lEV2KU2UFqMKrLWk-Gisnp5cTpI6bacsaihX8ysAEUS9ptc-aIrY/s1600/inst5.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;92&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDJMI8PP0V3va9NAyTEbRoP0YUw3z1fWGUU0584XqlBUpbB8jrO4PSaMY1FbGxbhL7akwyE-GZXE3gw5yzTTa04B4lEV2KU2UFqMKrLWk-Gisnp5cTpI6bacsaihX8ysAEUS9ptc-aIrY/s1600/inst5.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Thanks you hope it will help.</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/6157091648829233224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/setup-python-on-windows-platform.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/6157091648829233224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/6157091648829233224'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/setup-python-on-windows-platform.html' title='Setup Python on windows platform'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzTSk96eSWg70Cgp2rBuH2Z0RIJ2OS7c3G7y7CtTaZXpcJAms2fkIkj5r5qR99uSjOoj5dYQVu3OL9ganWht4eUggNSpXt6xdnSQKicDGgwvvi4MSZVvqMTX3Eu-hk1AvxE1PSK8KnTpE/s72-c/inst1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-3746234823549445957</id><published>2015-10-20T23:35:00.003-07:00</published><updated>2015-11-24T17:52:30.561-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>No more Python 2.8</title><content type='html'>I use python for my daily programming stuff and I am so happy I can 
use it in my daily programming stuff, Python language it so beautiful, 
effective and clean.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Why it&#39;s beautiful?&lt;/b&gt; because
 it&#39;s easy to learn, easy to implement, easy to extends (we can extends 
python using C or C++). It&#39;s good programming language for people who 
want to learn basic programming concepts. But don&#39;t forget to have deep 
concept in C programming language :D, C is important thing and one thing
 you need to know about python it made from C.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Why it&#39;s effective?&lt;/b&gt;
 python syntax and idiom is well mature. We can create complicated stuff
 with python using few lines of code. Python built in method is complete
 you don&#39;t really need third party library if you not use it on specific
 purpose.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Why it&#39;s clean?&lt;/b&gt; Python functions have 
no explicit begin or end, and no curly braces to mark where the function
 code starts and stops. The only delimiter is a colon (:) and the 
indentation of the code itself. Python block of code is separate with 
indentation not curly braces so it clean and you will always got clean 
code structure.&lt;br /&gt;
&lt;br /&gt;
But python 2.7 is the last python 2 
development and will not supported in the future python release, because
 python development team decided to support python 3 version only. Don&#39;t
 worry python 3.4 is best python version ever, you can convert code from
 python 2.7 to python 3. :-) smart.</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/3746234823549445957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/10/no-more-python-28.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/3746234823549445957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/3746234823549445957'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/10/no-more-python-28.html' title='No more Python 2.8'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-8689476234175401523</id><published>2015-02-03T23:43:00.000-08:00</published><updated>2015-11-24T17:52:56.813-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="sqlite"/><title type='text'>SQLite3 Review – Great for Beginners and Those Learning SQL</title><content type='html'>&lt;a href=&quot;http://www.essentialsql.com/sqlite3-review-great-for-beginners-and-those-learning-sql/&quot;&gt;Essentialsql.com&lt;/a&gt; SQLite3 is a compact free database you can use easily create and use a database.&amp;nbsp; Though SQLite3 is not a full-featured database, it supports a surprisingly large set of the SQL standard, and is&amp;nbsp;&lt;i style=&quot;margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;ideal for those just starting to learn SQL&lt;/i&gt;&amp;nbsp;as well for developers that need a simple database engine to plug into their applications.&amp;nbsp; As such, SQLite has become very popular with smart phone developers.&lt;br /&gt;
&lt;div style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;Learn SQL with SQLite&lt;/b&gt; &lt;br /&gt;
There are several reasons I feel that SQLite3 is suitable for beginners.&lt;br /&gt;
&lt;br /&gt;
The first is that you don’t need to be an expert to install and configure it.&amp;nbsp; In fact, getting SQLite3 to run is as simple as&amp;nbsp;&lt;a href=&quot;http://www.essentialsql.com/get-ready-to-learn-sql-how-to-install-sqlite-and-the-sample-database/&quot; style=&quot;color: #8800c4; margin: 0px; padding: 0px; word-wrap: break-word;&quot; target=&quot;_blank&quot; title=&quot;Get Ready to Learn SQL:  1. How to Install SQLite and the Sample Database&quot;&gt;downloading the program&lt;/a&gt;&amp;nbsp;and then running a simple command.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
sqlite3 EssentialSQL.db&lt;/blockquote&gt;
&lt;br /&gt;
This is all that is needed to start up the database engine and start using the essential SQL database.&lt;br /&gt;
&lt;br /&gt;
Second, the software is a really simple command line interface.&amp;nbsp; Now you may think that is a fault, but it isn’t, as our goal is to learn SQL.&amp;nbsp; And to really learn SQL you need to understand its commands and instructions (syntax).&amp;nbsp; SQLite lets you work distraction free with the essence of SQL.&lt;br /&gt;
&lt;br /&gt;
Also, SQLite runs many different computer systems such as Apple OS X, Linux, and Windows.&amp;nbsp; This was important to me, since I wanted to provide everyone with&amp;nbsp;&lt;a href=&quot;http://www.essentialsql.com/getting-started/&quot; style=&quot;color: #8800c4; margin: 0px; padding: 0px; word-wrap: break-word;&quot; target=&quot;_blank&quot; title=&quot;Getting Started&quot;&gt;easy to follow SQL lessons&lt;/a&gt;, and didn’t’ want to leave anyone out.&lt;br /&gt;
&lt;br /&gt;
The last reason I recommend SQLite to beginners is that it is free to use.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What Others Say about SQLite3&lt;/b&gt; &lt;br /&gt;
There are other free database engines you can use to learn SQL.&amp;nbsp; The most popular are Microsoft SQLExpress, MySQL, and Oracle Express.&lt;br /&gt;
&lt;br /&gt;
Each of these are excellent databases and I have no trouble recommending them to anyone.&amp;nbsp; If you look at the&amp;nbsp;&lt;a href=&quot;http://www.essentialsql.com/what-are-the-top-ten-database-engines/&quot; style=&quot;color: #8800c4; margin: 0px; padding: 0px; word-wrap: break-word;&quot; target=&quot;_blank&quot; title=&quot;What are the Top Ten Database Engines?&quot;&gt;Database Engine rankings&lt;/a&gt;, you’ll see these are the top three databases in popularity.&amp;nbsp; All three are full featured, and truly capable or supporting very large databases.&lt;br /&gt;
&lt;br /&gt;
Once you learn SQL using SQLite, my recommendation is to pick one of these three products to continue your education.&lt;br /&gt;
&lt;br /&gt;
What one would you choose next?&amp;nbsp; I would pick the database that your company or department uses.&amp;nbsp; Chances are it is either Oracle or Microsoft SQL.&amp;nbsp;&amp;nbsp; If you do a lot of work on the web, then I would gravitate towards MySQL.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SQLite3 Benefits&lt;/b&gt; &lt;br /&gt;
We covered some of the ways SQLite is suited for learning SQL; however, its benefits go beyond that.&amp;nbsp; Though SQLite is a compact database, it is meant for serious applications!&amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.airbus.com/&quot; style=&quot;color: #8800c4; margin: 0px; padding: 0px; word-wrap: break-word;&quot; target=&quot;_blank&quot;&gt;Airbus&lt;/a&gt;, the airplane manufacturer, even uses it on some flight software for their A350 line of aircraft.&amp;nbsp; Some benefits of SQLite3 include:&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;font-size: 16px; margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;
Small and Self-Contained&lt;/h3&gt;
No additional programs or components are required for it to run.&amp;nbsp; The database engine can run on any modern PC or Smartphone&lt;br /&gt;
&lt;br /&gt;
SQLite doesn’t require a separate computer process to run.&amp;nbsp; IT doesn’t rely on windows services, background daemons, nor separate computer hardware.&lt;br /&gt;
&lt;br /&gt;
TRANSLATION:&amp;nbsp; It is simple to install and use.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Portable&lt;/b&gt;&lt;br /&gt;
It is really simple to share databases. Just copy one file to do so.&amp;nbsp; This is what makes it easy for me to provide you with the essential SQL sample database.&lt;br /&gt;
&lt;br /&gt;
A SQLite database file is at home on Windows&amp;nbsp;as much as it is OS X.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Standards Aware&lt;/b&gt;&lt;br /&gt;
SQLite is based on the standard SQL language.&amp;nbsp; Some features are omitted (see below), but those implemented closely adhere to standards.&lt;br /&gt;
&lt;br /&gt;
This means what you learn, will easily translate to other database engines.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Public domain&lt;/b&gt;&lt;br /&gt;
SQLite isn’t owned by any company.&amp;nbsp; Instead of a software license, the code comes with a simple blessing:&lt;i style=&quot;margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i style=&quot;margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;May you do good and not evil&lt;/i&gt;&lt;i style=&quot;margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i style=&quot;margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;May you find forgiveness for yourself and forgive others&lt;/i&gt;&lt;i style=&quot;margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i style=&quot;margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;May you share freely, never taking more than you give.&lt;/i&gt;&amp;nbsp;&lt;/blockquote&gt;
Isn’t that refreshing?&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SQLite Cons&lt;/b&gt;&lt;br /&gt;
There are disadvantages to SQLite.&amp;nbsp; Since it is so compact and meant to run in a small space, some trade-offs were made.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Limited Data types&lt;/b&gt;&lt;br /&gt;
SQLite doesn’t support the date or timestamp data types.&amp;nbsp; This is a disadvantage as many SQL puzzles, thus learning opportunities, are out of our reach in the beginning.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SQL Language Support&lt;/b&gt;&lt;br /&gt;
There are several features not supported in SQLite.&amp;nbsp; Right Outer Joins aren’t supported nor are Full Outer Joins.&amp;nbsp; Since Left Outer Joins are supported, and are similar to Right Outer Joins, the opportunity to learn isn’t lost.&lt;br /&gt;
&lt;br /&gt;
It also isn’t easy to alter an existing table nor are there some referential integrity checks.&amp;nbsp; These are pretty important features to have to manage a production database.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Size Limitations&lt;/b&gt;&lt;br /&gt;
SQLite isn’t meant to support extremely large databases.&amp;nbsp; It isn’t able to scale to hundreds of users nor store gigabytes of data.&amp;nbsp; It isn’t suitable where you expect a large number of users to simultaneously modify data (high concurrency), nor where there is a large volume of transactions.&lt;br /&gt;
&lt;br /&gt;
In general I would say most reviewers have positive things to say about SQLite3.&amp;nbsp; All pretty much agree that SQLite isn’t meant to power your next ERP system (a large database), but is well suited for a personal database or one hosting several users. SQL does what it does well.&amp;nbsp; SQLite just works.&lt;br /&gt;
&lt;br /&gt;
While searching for a minimal database, alkoksha.org, found SQLite3 to be the best choice.&lt;br /&gt;
&lt;br /&gt;
SQLite.org recommends not using SQLite for a client/server application.&amp;nbsp; We agree.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Learning More About SQLite3&lt;/b&gt;&lt;br /&gt;
If you are curious to learn more about SQLite I would recommend you start here to begin our free course on learning SQL using SQLite3.&amp;nbsp; The course assumes you know nothing about programming, so anyone, really anyone who can drag a file onto their computer, can do the course.&lt;br /&gt;
&lt;br /&gt;
If you want read more about SQLite3, then I would recommend Using SQLite, by Jay A. Kreibich (affiliate link).&amp;nbsp; This book is well received by the community.&amp;nbsp; It is definitely more technical than my training classes, but is a great way to get into more detail about SQLite.&lt;/div&gt;
&lt;div class=&quot;post_content&quot; itemprop=&quot;articleBody&quot; style=&quot;color: #111111; font-family: Georgia, &#39;Times New Roman&#39;, Times, serif; font-size: 16px; line-height: 26px; margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;
&lt;ul style=&quot;list-style-type: square; margin: 0px 0px 26px 26px; padding: 0px; word-wrap: break-word;&quot;&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;post_content&quot; itemprop=&quot;articleBody&quot; style=&quot;color: #111111; font-family: Georgia, &#39;Times New Roman&#39;, Times, serif; font-size: 16px; line-height: 26px; margin: 0px; padding: 0px; word-wrap: break-word;&quot;&gt;
&lt;ul style=&quot;list-style-type: square; margin: 0px 0px 26px 26px; padding: 0px; word-wrap: break-word;&quot;&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/8689476234175401523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/02/sqlite3-review-great-for-beginners-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/8689476234175401523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/8689476234175401523'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/02/sqlite3-review-great-for-beginners-and.html' title='SQLite3 Review – Great for Beginners and Those Learning SQL'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-3700470099397891822</id><published>2015-01-26T18:40:00.000-08:00</published><updated>2015-11-24T17:53:19.766-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="manjaro"/><title type='text'>solving a start job is running for create volatile files and directories : manjaro linux</title><content type='html'>I have used &lt;a href=&quot;http://manjaro.github.io/about/&quot; target=&quot;_blank&quot;&gt;Manjaro Linux&lt;/a&gt; which is &lt;a href=&quot;https://www.archlinux.org/&quot; target=&quot;_blank&quot;&gt;Arch Linux&lt;/a&gt; based system for several month. Manjaro using roling system update, so we don&#39;t need to install new distribution to use latest version. We only need to upgrade through update manager.&lt;br /&gt;
&lt;br /&gt;
After several times I used roling update then I restart my system boot time take long time, and plymouth like freeze. When I press escape to view error message on boot time. I got this message.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
a start job is running for create volatile files and directories&lt;/blockquote&gt;
&amp;nbsp;I search internet but I got nothing to solve my problems, then I try to view my manjaro setting then I take look on kernel section, I know that my kernel is need to be upgrade. Manjaro system will notif recommended kernel version for installed system if newer kernel exist.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHexKgAI8xfIMWmzbZ_FW3CCBltsdoXZyInomf3tiRLQgRpkiYpTmG622JFR6SVl70f6S5t9qK9AmcUq7gyz8xqrriatbnmMw2ldYblslFfPITo6logxR9IA1nuxaHeuK19UDVNPyVofk/s1600/Screenshot+-+270115+-+09:33:42.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;310&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHexKgAI8xfIMWmzbZ_FW3CCBltsdoXZyInomf3tiRLQgRpkiYpTmG622JFR6SVl70f6S5t9qK9AmcUq7gyz8xqrriatbnmMw2ldYblslFfPITo6logxR9IA1nuxaHeuK19UDVNPyVofk/s1600/Screenshot+-+270115+-+09:33:42.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTgFWBswLukqzlCuwBrrLlBaaYcVsrNN5r2qcXlIOnJgst55RueMDHbdIL9N-phoAG9nysOc8FoqRFh4FvLQkoibFjq12A5KQRDd_PhESqthQIsxcVho5RfR4oLDR03joEhyD8EXcRGHc/s1600/Screenshot+-+270115+-+09:33:58.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;312&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTgFWBswLukqzlCuwBrrLlBaaYcVsrNN5r2qcXlIOnJgst55RueMDHbdIL9N-phoAG9nysOc8FoqRFh4FvLQkoibFjq12A5KQRDd_PhESqthQIsxcVho5RfR4oLDR03joEhyD8EXcRGHc/s1600/Screenshot+-+270115+-+09:33:58.png&quot; width=&quot;400&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Install Recommended kernel from kernel section, after installation finish I restart my system and&amp;nbsp; it&#39;s like a magic all error message and boot time back to normal :).&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
#good luck have fun &lt;/div&gt;
&lt;span id=&quot;goog_1337358786&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_1337358787&quot;&gt;&lt;/span&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/3700470099397891822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/solving-start-job-is-running-for-create.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/3700470099397891822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/3700470099397891822'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/solving-start-job-is-running-for-create.html' title='solving a start job is running for create volatile files and directories : manjaro linux'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHexKgAI8xfIMWmzbZ_FW3CCBltsdoXZyInomf3tiRLQgRpkiYpTmG622JFR6SVl70f6S5t9qK9AmcUq7gyz8xqrriatbnmMw2ldYblslFfPITo6logxR9IA1nuxaHeuK19UDVNPyVofk/s72-c/Screenshot+-+270115+-+09:33:42.png" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-8727957836677474939</id><published>2015-01-21T20:17:00.000-08:00</published><updated>2015-11-24T17:53:45.994-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu"/><title type='text'>The first Ubuntu Phone will go on sale in Europe in the second week of February.</title><content type='html'>Read original post &lt;a href=&quot;http://www.omgubuntu.co.uk/2014/12/bq-ubuntu-phone-launches-in-europe-this-february/?utm_source=website&amp;amp;utm_medium=carousel&amp;amp;utm_campaign=carousel&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Made by Spanish device company Bq, the handset will mark the first time that an Ubuntu Phone is&amp;nbsp;sold directly to consumers&lt;br /&gt;
&lt;h3 class=&quot;&quot;&gt;
The First Phone: Specifications&lt;/h3&gt;
For its first Ubuntu Phone Bq is launching a repurposed version of the its popular&amp;nbsp;&lt;a href=&quot;http://www.bq.com/gb/products/aquaris-e4-5.html&quot; target=&quot;_blank&quot; title=&quot;Bq product page for the e4.5 handset&quot;&gt;Aquaris e4.5 handset&lt;/a&gt;&amp;nbsp;preloaded with Ubuntu for Phones.&lt;br /&gt;
Unlike the version that developers can (and have) been downloading 
and flashing to their Nexus devices, the commercial version of Ubuntu on
 phones will ship with a number of differences in software, including 
new &lt;i&gt;‘Aggregator Scopes&lt;/i&gt;’, ‘&lt;i&gt;Today Scope’&lt;/i&gt;, and support for paid content.&lt;br /&gt;
Specifications wise the Aquaris e4.5 is a capable daily driver. It’s a stylish, well built and dependable handset.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;4.5-inch screen (qHD resolution @ 540×960)&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;1.3 GHz Quad Core ARM Cortex A7&amp;nbsp;(MediaTek)&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mali 400 GPU&amp;nbsp;@&amp;nbsp;500 MHz&amp;nbsp;(MediaTek)&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;8GB eMMC Storage&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;1GB RAM&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;2150 mAh Battery&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Dual micro-SIM&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
No, it’s not the most powerful&amp;nbsp;of device but, honestly, that’s good 
Ubuntu’s debut device needs to be accessible, to balance price and 
performance so that hesitant&amp;nbsp;developers and enthusiasts — the lifeblood 
of any burgeoning platform — can pick one up to tinker with &lt;i&gt;without&lt;/i&gt; needing to sell a body part.&lt;br /&gt;
&lt;div class=&quot;&quot;&gt;
Although Canonical hasn’t given us any firm price tag is has
 been suggested to us, with a wry wink and a cheeky smile, that buyers 
certainly won’t pay more than the ~€149 or so that Bq currently sells 
the&amp;nbsp;Android version at.&lt;/div&gt;
&lt;div class=&quot;&quot;&gt;
If anything, it is likely to sell for less.&lt;/div&gt;
&lt;h3&gt;
Looking Ahead&lt;/h3&gt;
&lt;div class=&quot;wp-caption alignright&quot; id=&quot;attachment_95995&quot; style=&quot;width: 350px;&quot;&gt;
&lt;img alt=&quot;The Bq Handset In Hand&quot; class=&quot;size-full wp-image-95995&quot; src=&quot;http://www.omgubuntu.co.uk/wp-content/uploads/2014/12/1418928246_full.jpeg&quot; height=&quot;200&quot; width=&quot;350&quot; /&gt;&lt;br /&gt;
&lt;div class=&quot;wp-caption-text&quot;&gt;
The Bq Handset In Hand&lt;/div&gt;
&lt;/div&gt;
The elephant in the room is the USA. Initially Bq will &lt;i&gt;only&lt;/i&gt;&amp;nbsp;sell
 their Ubuntu phone in Europe, and that through their website. US plans 
are yet to be divulged, and it’s not clear if it will be Bq, Meizu or an
 as yet unannounced partner jumping through the hoops required to launch
 a cellular device there.&lt;br /&gt;
Looking ahead, I think it’s likely that we’ll see Bq launch an Ubuntu
 version of its 4G-equipped Aquaris 5 model later in the year. The&amp;nbsp;model
 is a little larger than the e4.5 and features an HD IPS screen screen 
and marginally faster processor.&amp;nbsp;It’s this device that was launched a&lt;a href=&quot;http://www.omgubuntu.co.uk/2014/11/bq-event-delivers-expecting-nothing-ubuntu-phone&quot; title=&quot;The ‘Mystery’ Bq Event Went Big on Android, Silent on Ubuntu&quot;&gt;t Bq’s ‘mystery press event’ last month, &lt;/a&gt;alongside several new Android tablets.&lt;br /&gt;
A video advert directed by renowned Spanish filmmaker &lt;i&gt;Álex de la Iglesia&lt;/i&gt; premiered at that event — an advert I’ve a hunch we’ll be seeing a little more in the near future… ;)</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/8727957836677474939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/the-first-ubuntu-phone-will-go-on-sale.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/8727957836677474939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/8727957836677474939'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/the-first-ubuntu-phone-will-go-on-sale.html' title='The first Ubuntu Phone will go on sale in Europe in the second week of February.'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-3863244932063034493</id><published>2015-01-20T03:49:00.000-08:00</published><updated>2015-11-24T17:54:19.136-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="manjaro"/><category scheme="http://www.blogger.com/atom/ns#" term="xfce"/><title type='text'>Manjaro XFCE Post Installation Tips and Tricks </title><content type='html'>&lt;h3 class=&quot;post-title entry-title&quot; itemprop=&quot;name&quot;&gt;
&lt;/h3&gt;
&lt;div class=&quot;post-header&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To read original article go to &lt;a href=&quot;http://mr-greens.blogspot.com/2013/06/manjaro-xfce-post-installation-tips-and.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;It&#39;s
 nearly a year since my last post, a lot of things had happened in 
between, Placement preparation, couple of interviews, six month 
internship in Blackberry Platform at&amp;nbsp;&lt;a href=&quot;http://www.payoda.com/&quot; target=&quot;_blank&quot;&gt;Payoda Technologies&lt;/a&gt;&amp;nbsp;
 and finally completion of my studies. During this period a lot of 
distros had been released but I stayed with the stable Opensuse, but 
then I felt KDE version of opensuse is little bit heavy, which can be 
felt during both start-up and during normal day to day usage(say 
Eclipse+amarok+chrome) even with 4GB RAM and i3 Processor.&lt;/span&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;I started my quest for &quot;The best GNU/Linux OS&quot; with &lt;a href=&quot;http://distrowatch.com/&quot;&gt;distrowatch.com&lt;/a&gt;.
 Since I wanted a lighter distro but not certainly like Puppy/Tiny and 
no Ubuntu/Debian forks then by default I left with Arch. But the fear of
 &amp;nbsp;two earlier failed attempts to install Arch forced me to try arch fork
 than arch. Seeing&amp;nbsp;&lt;a href=&quot;http://distrowatch.com/table.php?distribution=manjaro&quot; target=&quot;_blank&quot;&gt;Manjaro&amp;nbsp;&lt;/a&gt;&amp;nbsp;Linux description &quot;&lt;span style=&quot;background-color: yellow;&quot;&gt;Manjaro Linux is a desktop-oriented, user-friendly distribution based on Arch Linux&lt;/span&gt;&quot; ,&amp;nbsp;I thought I would give it a try. Downloaded and Installed &lt;b&gt;manjaro-xfce-0.8.5.1-x86_64 &lt;/b&gt;from &lt;a href=&quot;http://manjaro.org/get-manjaro/&quot; target=&quot;_blank&quot;&gt;Manjaro site&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The first thing I 
noticed with Manjaro is, it&#39;s fast start-up&amp;nbsp;and shutdown time, it is 
comparatively faster than opensuse. Here are the some of tricks which I 
had done to achieve what&#39;s in their description&amp;nbsp;&lt;b style=&quot;background-color: white;&quot;&gt;user-friendly distribution. NOTE: &lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;i&gt;No
 Graphics driver installation tips are given because author himself 
followed the steps listed in Beginner&#39;s guide and finally ended with 
blank screen even though he only have Intel&#39;s Integrated graphics card&lt;/i&gt;&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&lt;i&gt;.&lt;/i&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: #fdffe3;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: #fdffe3;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;1.&lt;/span&gt; &lt;/b&gt;&lt;b style=&quot;background-color: white; line-height: 18.1875px;&quot;&gt;Synchronize &amp;nbsp;and Update Manjaro repositories using pacman&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; line-height: 16px;&quot;&gt;Pacman&lt;/span&gt;&lt;span style=&quot;background-color: white; line-height: 16px;&quot;&gt;&amp;nbsp;is the&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; line-height: 16px;&quot;&gt;package manager used in Manjaro/Arch.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span class=&quot;pln&quot;&gt;sudo pacman &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Syu&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;verdana&amp;quot; , sans-serif; line-height: 16px; white-space: normal;&quot;&gt;For handy pacman tips refer&amp;nbsp;&lt;a href=&quot;http://forum.manjaro.org/index.php?action=profile;u=9&quot; style=&quot;background-color: transparent; font-family: Verdana, sans-serif; white-space: normal;&quot; target=&quot;_blank&quot;&gt;@YF-Dogan&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; white-space: normal;&quot;&gt;&#39;s&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; white-space: normal;&quot;&gt;&amp;nbsp;thread from manjaro&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://forum.manjaro.org/index.php?topic=1705.0&quot; style=&quot;background-color: transparent; font-family: Verdana, sans-serif; white-space: normal;&quot; target=&quot;_blank&quot;&gt;forum&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; white-space: normal;&quot;&gt;&amp;nbsp;and the&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://wiki.manjaro.org/index.php?title=Pacman_Tips&quot; style=&quot;background-color: transparent; font-family: Verdana, sans-serif; white-space: normal;&quot; target=&quot;_blank&quot;&gt;wiki&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;span style=&quot;background-color: white; line-height: 16.5px; white-space: nowrap;&quot;&gt;&lt;b&gt;2.Mounting windows partition with Read and write permission.&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; line-height: 16.5px; white-space: nowrap;&quot;&gt;i)&lt;span style=&quot;background-color: transparent;&quot;&gt;To achieve write permissions for other users than root, &lt;/span&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;you will need to install &lt;a href=&quot;https://en.wikipedia.org/wiki/NTFS-3G&quot; target=&quot;_blank&quot;&gt;ntfs-3g&lt;/a&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; line-height: 16.5px; white-space: nowrap;&quot;&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;which also &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; line-height: 16.5px; white-space: nowrap;&quot;&gt;will install&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; line-height: 16.5px; white-space: nowrap;&quot;&gt;&amp;nbsp;the fuse package in order to work.&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;b style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;font-size: xx-small;&quot;&gt;sudo pacman &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;font-size: xx-small;&quot;&gt;Sy&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt; ntfs&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;font-size: xx-small;&quot;&gt;3g&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;ii) List all available disk partitions&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;blizzard@linuxbox &lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;font-size: xx-small;&quot;&gt;Desktop&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;$ blkid&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;sda1&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; LABEL&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;System Reserved&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; UUID&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;F088C67D88C64238&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; TYPE&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;ntfs&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;sda2&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; UUID&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;3C804D34804CF644&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; TYPE&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;ntfs&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;sda4&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; UUID&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;A80E38E70E38B064&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; TYPE&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;ntfs&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;sda5&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; UUID&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;1da4f64f-3576-4caf-8cb8-e46f0514cd21&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; TYPE&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;ext4&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;sda6&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; LABEL&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;swap&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; UUID&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;28b7a025-ffc8-41aa-9244-7d12061af511&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; TYPE&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;swap&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;sda7&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; UUID&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;a7944df5-3f69-4d94-bab6-a4fe76ee276f&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; TYPE&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;ext4&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;sr1&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; UUID&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;2012-03-22-12-00-00-00&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; LABEL&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;Mobile Partner&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; TYPE&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;iso9660&quot;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;iii) Create Mount point&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;[blizzard@linuxbox Desktop]$ sudo mkdir -v /mnt/Storage&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;mkdir&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; created directory &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;‘/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;mnt&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Storage&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;’&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
iv) Add an /etc/fstab entry for any partition listed in `blkid`&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;e.g) For entry&amp;nbsp;/dev/sda4: UUID=&quot;A80E38E70E38B064&quot; TYPE=&quot;ntfs&quot; as shown below:
&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;com&quot; style=&quot;font-size: xx-small;&quot;&gt;#/dev/sda4&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-size: xx-small; white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;UUID&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;A80E38E70E38B064 &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;mnt&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;typ&quot; style=&quot;font-size: xx-small;&quot;&gt;Storage&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt; ntfs&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;font-size: xx-small;&quot;&gt;3g&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt; &amp;nbsp;defaults&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;umask&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;font-size: xx-small;&quot;&gt;077&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;uid&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;font-size: xx-small;&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;font-size: xx-small;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;font-size: xx-small;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;3. Install &lt;a href=&quot;http://en.wikipedia.org/wiki/Chromium_%28web_browser%29&quot; target=&quot;_blank&quot;&gt;Chromium&lt;/a&gt; (Open source version of Google Chrome).&lt;/b&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span class=&quot;pln&quot;&gt; &lt;span style=&quot;font-size: xx-small;&quot;&gt;&amp;nbsp;sudo pacman &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;font-size: xx-small;&quot;&gt;S chromium&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;font-size: xx-small;&quot;&gt;.&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;b&gt;4. Install other necessary utilities&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;b style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;span class=&quot;pln&quot;&gt;sudo pacman &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;S vim clementine osmo libreoffice&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;impress pinta xchm&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;vim - &lt;/b&gt;Text editor.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;clementine - &lt;/b&gt;Music player.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;osmo - &lt;/b&gt;Personal calendar, note taking, todo list application.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;libreoffice-impress - &lt;/b&gt;Presentation tool.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;pinta - &lt;/b&gt;An alternative to GIMP(Photo editing).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;xchm&lt;/b&gt;&amp;nbsp;- CHM reader.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;5. Automounting Removable disks&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-weight: bold; white-space: pre;&quot;&gt; &lt;/span&gt;Goto&amp;nbsp;Settings-&amp;gt;Settings Manager -&amp;gt; Removable Drives and Media -&amp;gt; Mount removable drives when hot-plugged.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOtmbqAg0rwGYslGOttLIf2JbgNhU8ldodsu76La0_Rem1ClpcDZpktsbOjSLd9UfuqF3kQrojiZqaGXCOOcW2iDHK0omqRFRjbx1WnDRhITO1k8lPpuRnHF2X_-s2wVBrqkUIwobYxYI/s1600/automount.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;382&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOtmbqAg0rwGYslGOttLIf2JbgNhU8ldodsu76La0_Rem1ClpcDZpktsbOjSLd9UfuqF3kQrojiZqaGXCOOcW2iDHK0omqRFRjbx1WnDRhITO1k8lPpuRnHF2X_-s2wVBrqkUIwobYxYI/s400/automount.png&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;6. Installing Dropbox&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: xx-small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;pln&quot;&gt;$&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span class=&quot;pln&quot;&gt;sudo yaourt &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;S dropbox dropbox&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;cli&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: xx-small;&quot;&gt;&lt;b style=&quot;white-space: normal;&quot;&gt;&lt;span class=&quot;pln&quot;&gt;$&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;b style=&quot;white-space: normal;&quot;&gt;&lt;span class=&quot;pln&quot;&gt;dropboxd &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;&amp;amp;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Refer:&amp;nbsp;&lt;a href=&quot;http://pfigue.github.io/blog/2012/12/24/installing-dropbox-in-arch-linux/&quot;&gt;http://pfigue.github.io/blog/2012/12/24/installing-dropbox-in-arch-linux/&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;7.Desktop and Workspace Shortcut Keys&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;By default the shortcut key used to minimize desktop is &lt;i&gt;ctrl+alt+d.&lt;/i&gt;&amp;nbsp;You can change the shortcut key by going to&amp;nbsp;Settings-&amp;gt;settings Manager-&amp;gt;Window Manager and assigning the shortcut key.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj54RQ9hSxBGJ2DJ1oDrMpq-WTuy9KI05_Kb-F0-31ou7dTqMtgiq4VIDOK7gJE9mqpFh7fsYOOOlJETFYArmNwDKItt0eX60TOD0GCsczAuRJJnyZUhzT_J2bV1e4lrkaxQcsCJXWRuSQ/s1600/minimize+to+desktop.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj54RQ9hSxBGJ2DJ1oDrMpq-WTuy9KI05_Kb-F0-31ou7dTqMtgiq4VIDOK7gJE9mqpFh7fsYOOOlJETFYArmNwDKItt0eX60TOD0GCsczAuRJJnyZUhzT_J2bV1e4lrkaxQcsCJXWRuSQ/s400/minimize+to+desktop.png&quot; width=&quot;362&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The shortcut keys for 
&quot;workspace+&quot; and &quot;Move window to workspace+&quot; can be assigned based on 
the&amp;nbsp;user preference. My favorite shortcut keys for &quot;workspace[0-4]&quot; are 
&quot;&amp;lt;Alt&amp;gt;+[1-4]&quot; and &quot;Move window to workspace[1-4]&quot; are 
&quot;&amp;lt;super&amp;gt;+[1-4]&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;8.Setting shortcut for Terminal&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Goto Settings-&amp;gt;settings Manager-&amp;gt;Keyboard-&amp;gt;Application Shortcuts,&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;click Add-&amp;gt; Type &quot;xfce4-terminal&quot; and click &quot;ok&quot;, after that assign whatever shortcut you want.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjidEhiEiVBmzF-CIl30THnRClw7ZbXxT9viktHpKOK216vGi2WgxfI5PCkTsLH_ycGoBf2683ZPW7TplR96hsEOmZOYUIeS1CwG7zDX3FVwSE8jrYgs8IpC2QrfEzpseXyCa4-x7-B3ok/s1600/terminal.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;326&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjidEhiEiVBmzF-CIl30THnRClw7ZbXxT9viktHpKOK216vGi2WgxfI5PCkTsLH_ycGoBf2683ZPW7TplR96hsEOmZOYUIeS1CwG7zDX3FVwSE8jrYgs8IpC2QrfEzpseXyCa4-x7-B3ok/s400/terminal.png&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;8. Stop Gedit from creating backup copy of files during each save&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Goto Gedit Edit-&amp;gt;Preferences-&amp;gt;Editor-&amp;gt; Uncheck &quot;Create a backup copy of files before saving&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9BOcH0XuHu4JBAoww8knaVRb3PIcYp0JJa0qPOEPy1Usw1r46VzZdsj0KDF60XZuKBRx5tZhiKAZX0xfQrb23TJMslU2FQISKviert687bQwk84YSXCIfXg2zreXUjCE-5urE4NbwLQ4/s1600/gedit.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9BOcH0XuHu4JBAoww8knaVRb3PIcYp0JJa0qPOEPy1Usw1r46VzZdsj0KDF60XZuKBRx5tZhiKAZX0xfQrb23TJMslU2FQISKviert687bQwk84YSXCIfXg2zreXUjCE-5urE4NbwLQ4/s400/gedit.png&quot; width=&quot;335&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;9. Enable Touchpad Horizontal and &amp;nbsp;Vertical &amp;nbsp;scrolling.&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;span style=&quot;font-size: xx-small;&quot;&gt;$&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;pln&quot;&gt;sudo gedit &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;etc&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;X11&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;xorg&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;conf&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;lit&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;synaptics&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;conf&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Add the following content&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: xx-small;&quot;&gt;&lt;b&gt;&lt;span class=&quot;typ&quot;&gt;Section&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;InputClass&quot;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Identifier&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;touchpad catchall&quot;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Driver&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;synaptics&quot;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;MatchIsTouchpad&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;on&quot;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Option&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;TapButton1&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Option&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;VertEdgeScroll&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;typ&quot;&gt;Option&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;HorizEdgeScroll&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;pln&quot;&gt;
&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;typ&quot;&gt;EndSectio&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;typ&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
For details refer &lt;a href=&quot;http://wiki.manjaro.org/index.php?title=Enable_Touchpad_Horizontal_and_Vertical_Scrolling&quot; style=&quot;font-weight: bold;&quot; target=&quot;_blank&quot;&gt;Manjaro Wiki&lt;/a&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;and&lt;b&gt; &lt;/b&gt;&lt;a href=&quot;https://wiki.archlinux.org/index.php/Touchpad_Synaptics&quot; style=&quot;font-weight: bold;&quot; target=&quot;_blank&quot;&gt;Arch Wiki&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;10. Installing Uncomplicated Firewall(ufw)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The launchpad description of &lt;a href=&quot;https://launchpad.net/ufw&quot; target=&quot;_blank&quot;&gt;ufw &lt;/a&gt;says &quot;&lt;span style=&quot;background-color: white; color: #333333; font-size: 16px; line-height: 18px;&quot;&gt;Ufw
 stands for Uncomplicated Firewall, and is program for managing a 
netfilter firewall. It provides a command line interface and aims to be 
uncomplicated and easy to use.&lt;/span&gt;&quot;. As the name says the program is easy to install and configure it in manjaro.&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint prettyprinted&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp; sudo yaourt &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;S gufw&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
For detailed configuration steps follow the &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;@&lt;a href=&quot;http://forum.manjaro.org/index.php?action=profile;u=526&quot; target=&quot;_blank&quot;&gt;handy&lt;/a&gt;&#39;s post from &lt;a href=&quot;http://forum.manjaro.org/index.php?topic=2543.0&quot; target=&quot;_blank&quot;&gt;Manjaro forum&lt;/a&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;and &lt;a href=&quot;https://wiki.ubuntu.com/UncomplicatedFirewall&quot; target=&quot;_blank&quot;&gt;wiki&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;For more please refer&lt;/b&gt;&lt;/span&gt;&lt;/h4&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;http://forum.manjaro.org/&quot; target=&quot;_blank&quot;&gt;Manjaro Forum&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href=&quot;http://wiki.manjaro.org/index.php?title=Main_Page&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Manjaro Wiki&amp;nbsp;&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;irc.freenode.net - #manjaro&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;b style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Customizing Manjaro&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;&lt;a href=&quot;https://wiki.archlinux.org/index.php/Maximizing_Performance&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Maximizing Arch Linux Performance&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://forum.manjaro.org/index.php?board=15.0&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Tutorials from Manjaro Forum&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Some Random Learnings&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;XNOISE &quot;GstError parsed: configured audiosink audiobin is not working.&quot;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; white-space: pre;&quot;&gt; 
&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;i&gt;sudo&amp;nbsp;pacman -S gst-plugins-base&lt;/i&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://forum.manjaro.org/index.php?topic=992.0&quot; style=&quot;font-family: Verdana, sans-serif;&quot; target=&quot;_blank&quot;&gt;Fix for Multimedia mute button problem&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;i&gt;Enable Multimedia Keys support for XNoise&lt;/i&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; white-space: pre;&quot;&gt;&lt;i&gt; &lt;/i&gt;
&lt;i&gt;Goto &lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;i&gt;Edit-&amp;gt; Preferences -&amp;gt; Settings#Addditional Section-&amp;gt;Media Control Keys(Plugin)&lt;/i&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://forum.manjaro.org/index.php?topic=3692.0&quot; style=&quot;font-family: Verdana, sans-serif;&quot; target=&quot;_blank&quot;&gt;UTC/local time zone conflicts when dual booting with windows 7&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/3863244932063034493/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/manjaro-xfce-post-installation-tips-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/3863244932063034493'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/3863244932063034493'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/manjaro-xfce-post-installation-tips-and.html' title='Manjaro XFCE Post Installation Tips and Tricks '/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOtmbqAg0rwGYslGOttLIf2JbgNhU8ldodsu76La0_Rem1ClpcDZpktsbOjSLd9UfuqF3kQrojiZqaGXCOOcW2iDHK0omqRFRjbx1WnDRhITO1k8lPpuRnHF2X_-s2wVBrqkUIwobYxYI/s72-c/automount.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-6138470922739640423</id><published>2015-01-17T21:38:00.000-08:00</published><updated>2015-11-24T17:54:43.088-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="manjaro"/><title type='text'>Manjaro Linux: Arch For People Who Don’t Have Time</title><content type='html'>&lt;span style=&quot;font-size: 14px; line-height: 1.5em;&quot;&gt;I am manjaro Linux user, and want to share how arch linux based system transform into friendly distro for end user.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: 14px; line-height: 1.5em;&quot;&gt;This article originaly from &lt;a href=&quot;http://www.makeuseof.com/tag/manjaro-linux-arch-people-dont-time/&quot; target=&quot;_blank&quot;&gt;make use of&lt;/a&gt; site. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: 14px; line-height: 1.5em;&quot;&gt;There are plenty of things that &lt;/span&gt;&lt;a href=&quot;http://www.makeuseof.com/tag/arch-linux-letting-you-build-your-linux-system-from-scratch/&quot; style=&quot;font-size: 14px; line-height: 1.5em;&quot;&gt;make Arch Linux highly appealing&lt;/a&gt;&lt;span style=&quot;font-size: 14px; line-height: 1.5em;&quot;&gt;
 to users: it’s always up-to-date, it’s a rolling release, and there’s 
tons of software available for it in its repositories. But what isn’t so
 appealing is the learning curve and pure difficulty of setting up an 
Arch system. If you want the best aspects of Arch, without the bad 
parts, you need Manjaro Linux.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: center;&quot;&gt;
About &lt;a href=&quot;http://manjaro.org/&quot;&gt;Manjaro Linux&lt;/a&gt;&lt;/h2&gt;
Manjaro Linux is an Arch-based distribution, meaning that it runs on 
the same backbone and the same repositories as Arch itself. It also 
implements the rolling release upgrade model, meaning that you never 
have to perform a major upgrade from “release 1″ to “release 2″ – just 
update your packages and you’ll be up-to-date.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;i&gt;&lt;span class=&quot;post__img-holder&quot;&gt;&lt;img alt=&quot;majaro-logo&quot; class=&quot;aligncenter size-full wp-image-325124&quot; src=&quot;http://cdn.makeuseof.com/wp-content/uploads/2014/03/majaro-logo.png?79af87&quot; height=&quot;39&quot; width=&quot;180&quot; /&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;img__sharer&quot;&gt;
&lt;i&gt;&lt;/i&gt;&lt;/div&gt;
However, unlike Arch, it doesn’t require that users build up systems 
on their own. This isn’t to say that setting up the Arch way is a bad 
thing, or that it’s too difficult – there’s plenty of documentation for 
the job. But some people simply don’t have the time, regardless of their
 skill level.&lt;br /&gt;
There’s a lot of fuss among Arch users whether they should support 
Manjaro, and while some believe that it goes against everything Arch 
stands for, I think it’s a good option for those who want it.&lt;br /&gt;
Also unlike Arch, there are some defaults when it comes to the 
included software. For example, Manjaro defaults to the Xfce desktop 
environment (which &lt;a href=&quot;http://www.makeuseof.com/tag/xfce-lightweight-speedy-fullyfledged-linux-desktop/&quot;&gt;is lightweight and awesome&lt;/a&gt;), although official Openbox,(a &lt;a href=&quot;http://www.makeuseof.com/tag/need-a-fresh-desktop-environment-for-linux-try-openbox-or-xmonad/&quot;&gt;very minimal desktop environment&lt;/a&gt;), and KDE (a &lt;a href=&quot;http://www.makeuseof.com/pages/guide-to-kde-the-other-linux-desktop&quot;&gt;desktop environment with lots of eye candy&lt;/a&gt;)&amp;nbsp;versions are available as well. Other desktop environments, such as Gnome, are available as “Community Editions”.&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Don’t Fear the Beta!&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span class=&quot;post__img-holder&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;manjaro_installer&quot; class=&quot;aligncenter size-full wp-image-324624&quot; src=&quot;http://cdn.makeuseof.com/wp-content/uploads/2014/03/manjaro_installer.jpg?79af87&quot; height=&quot;273&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Technically speaking, Manjaro is still a beta distribution – its version
 sits at 0.8.9 at time of writing. This shouldn’t push away any 
potential users. The main reason why Manjaro is still considered a beta 
distribution is because of the Manjaro additions to the otherwise stable
 Arch packages that are installed. Things like the Manjaro installer and
 the Pacman (package manager) graphical frontend are still beta, but 
everything else that is on the system are stable versions of the 
software that Arch offers in its repositories.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
The User Experience&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span class=&quot;post__img-holder&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;manjaro_greeting&quot; class=&quot;aligncenter size-full wp-image-324620&quot; src=&quot;http://cdn.makeuseof.com/wp-content/uploads/2014/03/manjaro_greeting.jpg?79af87&quot; height=&quot;269&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
When you first launch the distribution, you’ll be greeted with a simple 
message welcoming you to the system. It’ll also provide you with several
 buttons that send you to certain websites, or the installer. Otherwise,
 you can close this message and begin exploring.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span class=&quot;post__img-holder&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;manjaro_app_menu&quot; class=&quot;aligncenter size-full wp-image-324618&quot; src=&quot;http://cdn.makeuseof.com/wp-content/uploads/2014/03/manjaro_app_menu.jpg?79af87&quot; height=&quot;400&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Manjaro comes with a familar applications menu which initially displays 
your favorite applications, and then all of the usual categories. 
Navigation is easy and pretty enjoyable, primarily because it doesn’t 
get in your way.
The default software is pretty much what you’d expect for a regular 
full Linux distribution – Firefox, Thunderbird, and LibreOffice are all 
included. This is slightly surprisingly for a Xfce desktop – 
distributions using it &amp;nbsp;tend to choose more lightweight applications as 
the defaults. Manjaro also includes GIMP, Steam, and VLC Media Player.&lt;br /&gt;
By the way, for those who are exploring and happen to come upon a 
prompt asking for root permissions, the root password in the live 
environment is “manjaro”.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Installing Software&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span class=&quot;post__img-holder&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;manjaro_pacman&quot; class=&quot;aligncenter size-full wp-image-324621&quot; src=&quot;http://cdn.makeuseof.com/wp-content/uploads/2014/03/manjaro_pacman.jpg?79af87&quot; height=&quot;254&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Of course, you’ll be interested in knowing how installing packages goes.
 It worked just fine for me – no issues whatsoever. Manjaro actually 
uses its own repositories rather than piggybacking off of Arch’s 
repositories, but it imports Arch’s packages into its own to maintain 
compatibility. It also allows the project to perform some more testing 
than Arch does before putting their own “stable” label on the packages.
Maintaining compatibility with Arch also allows it to use &lt;a href=&quot;https://aur.archlinux.org/&quot;&gt;the Arch User Repository&lt;/a&gt;,
 the one repository where anyone can submit their own packages that 
aren’t found in the official repositories. Thankfully, but Manjaro’s 
repositories, as well as the AUR, can be accessed from the graphical 
package manager that comes with Manjaro — just enable the AUR checkbox 
and you’ll be looking at all the packages from both sources.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Conclusion&lt;/h2&gt;
Again, I really think that Manjaro is a great solution for those who 
like Arch’s updated packages, rolling release updates, and massive 
repositories but don’t enjoy the time requirements of installing 
everything from the ground up and maintaining the system via 
configuration files. If you’re not sure whether you’d be interested in 
using Manjaro, the best way to find out is to try it out &lt;a href=&quot;http://www.makeuseof.com/tag/linux-live-usb-creator-easily-boot-linux-flash-drive/&quot;&gt;from a USB flash drive&lt;/a&gt; or &lt;a href=&quot;http://www.makeuseof.com/pages/how-to-use-virtualbox&quot;&gt;within a virtual machine&lt;/a&gt;.&lt;br /&gt;
What’s your opinion of Manjaro? Do you think it could grow into a major distribution? Let us know in the comments!</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/6138470922739640423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/manjaro-linux-arch-for-people-who-dont.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/6138470922739640423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/6138470922739640423'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/manjaro-linux-arch-for-people-who-dont.html' title='Manjaro Linux: Arch For People Who Don’t Have Time'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-6357232409142588049</id><published>2015-01-17T21:20:00.001-08:00</published><updated>2015-11-24T17:55:17.515-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="game"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><title type='text'>Scary Steam for Linux bug erases all the personal files on your PC</title><content type='html'>&lt;span itemprop=&quot;articleBody text&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;section class=&quot;page&quot;&gt;
&lt;b&gt;Original Article From &lt;a href=&quot;http://www.pcworld.com/article/2871653/scary-steam-for-linux-bug-erases-all-the-personal-files-on-your-pc.html&quot; target=&quot;_blank&quot;&gt;pcworld&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If you’re a Steam fan running Linux, the last thing you’ll want to do
 in the next few days is mess with your Steam files. Users on &lt;a href=&quot;https://github.com/ValveSoftware/steam-for-linux/issues/3671&quot;&gt;Valve’s GitHub Steam for Linux page&lt;/a&gt;
 are complaining about a nasty bug that has the potential to wipe out 
every single personal file on your PC. Even worse, users say the bug 
will even wipe out documents on USB connected drives. So much for local 
backups.&lt;br /&gt;

&lt;b&gt;The impact on you at home:&lt;/b&gt; The obvious implication 
if you’re running Steam on Linux is to be wary of the program right now.
 As a precaution, don’t connect any local external hard drives while 
you’re running Steam. Users complaining of this bug appear to have moved
 their &lt;code&gt;.steam&lt;/code&gt;&amp;nbsp;or &lt;code&gt;~/.local/share/steam directories&lt;/code&gt;, or invoked Steam’s Bash script with the &lt;code&gt;—reset&lt;/code&gt; option enabled.&lt;br /&gt;

&lt;blockquote&gt;
&lt;b&gt;UPDATE:&lt;/b&gt;&amp;nbsp;&lt;i&gt;Valve gave us the following statement: 
&quot;So far we have had a handful of users report this issue, after they 
manually moved their Steam install. We have not been able to reproduce 
the reported issue, but we are adding some additional checks to ensure 
this is not possible while we continue to investigate. If anyone else 
has experienced this or has more information, they should email 
linux@valvesoftware.com.&quot;&lt;/i&gt;&lt;/blockquote&gt;
&lt;h2&gt;
Ouch&lt;/h2&gt;
Steam’s bug appears to be caused by a line in the Steam.sh Bash script: &lt;code&gt;rm -rf “$STEAMROOT/“*&lt;/code&gt;. That command is a basic Bash instruction that tells the computer to remove the &lt;i&gt;STEAMROOT&lt;/i&gt; directory and all its sub-directories (folders).&lt;br /&gt;

That’s all well and good, but the issue is that if the &lt;i&gt;STEAMROOT&lt;/i&gt; folder is not there then the computer interprets the command as &lt;code&gt;rm -rf “/“*&lt;/code&gt;, as first reported by &lt;a href=&quot;http://www.bit-tech.net/news/gaming/2015/01/16/steam-for-linux-bug/1&quot;&gt;Bit-Tech&lt;/a&gt;.
 If you’re not familiar with Bash, that command tells the system to 
delete everything on your hard drive starting from the root directory.&lt;br /&gt;

The saving grace for Linux users is that you can only erase files you
 have write permissions over. That means the system itself can’t be 
erased, but pretty much all of a user’s files—including photos and 
personal documents—would be at risk.&lt;br /&gt;

Ironically, the instruction at issue is preceded by a comment from the developer: &lt;code&gt;# Scary!&lt;/code&gt;.&lt;br /&gt;

Indeed.&lt;br /&gt;

&lt;i&gt;Editor&#39;s note: This article originally published on 1/16/15, but was updated on 1/17/15 to include Valve&#39;s statement.&lt;/i&gt;&lt;br /&gt;

 &lt;/section&gt;</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/6357232409142588049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/scary-steam-for-linux-bug-erases-all.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/6357232409142588049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/6357232409142588049'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/scary-steam-for-linux-bug-erases-all.html' title='Scary Steam for Linux bug erases all the personal files on your PC'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-546569934104833329</id><published>2015-01-17T07:45:00.000-08:00</published><updated>2015-11-24T17:55:42.464-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="tutorial"/><title type='text'>Porting Code to Python 3 with 2to3</title><content type='html'>&lt;h2 id=&quot;divingin&quot;&gt;
Diving In&lt;/h2&gt;
&lt;div class=&quot;f&quot;&gt;
So much has changed between Python 2 and Python 3, there are vanishingly few programs that will run unmodified under both. But don’t despair! To help with this transition, Python 3 comes with a utility script called &lt;code&gt;2to3&lt;/code&gt;, which takes your actual Python 2 source code as input and auto-converts as much as it can to Python 3. &lt;a href=&quot;https://www.blogger.com/case-study-porting-chardet-to-python-3.html#running2to3&quot;&gt;Case study: porting &lt;code&gt;chardet&lt;/code&gt; to Python 3&lt;/a&gt; describes how to run the &lt;code&gt;2to3&lt;/code&gt; script, then shows some things it can’t fix automatically. This appendix documents what it &lt;i&gt;can&lt;/i&gt; fix automatically.&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2 id=&quot;unicodeliteral&quot;&gt;
Unicode string literals&lt;/h2&gt;
&lt;/div&gt;
In Python 2, &lt;code&gt;&lt;dfn&gt;print&lt;/dfn&gt;&lt;/code&gt; was a statement. Whatever you wanted to print simply followed the &lt;code&gt;print&lt;/code&gt; keyword. In Python 3, &lt;a href=&quot;https://www.blogger.com/your-first-python-program.html#divingin&quot;&gt;&lt;code&gt;print()&lt;/code&gt; is a function&lt;/a&gt;. Whatever you want to print, pass it to &lt;code&gt;print()&lt;/code&gt; like any other function.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print()&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print 1&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print(1)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print 1, 2&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print(1, 2)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print 1, 2,&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print(1, 2, end=&#39; &#39;)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print &amp;gt;&amp;gt;sys.stderr, 1, 2, 3&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;print(1, 2, 3, file=sys.stderr)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;To print a blank line, call &lt;code&gt;print()&lt;/code&gt; without any arguments.
&lt;/li&gt;
&lt;li&gt;To print a single value, call &lt;code&gt;print()&lt;/code&gt; with one argument.
&lt;/li&gt;
&lt;li&gt;To print two values separated by a space, call &lt;code&gt;print()&lt;/code&gt; with two arguments.
&lt;/li&gt;
&lt;li&gt;This one is a little tricky. In Python 2, if you ended a &lt;code&gt;print&lt;/code&gt; statement with a comma, it would print the values separated by spaces, then print a trailing space, then stop without printing a carriage return. (Technically, it’s a little more complicated than that. The &lt;code&gt;print&lt;/code&gt; statement in Python 2 used a now-deprecated attribute called &lt;var&gt;softspace&lt;/var&gt;. Instead of printing a space, Python 2 would set &lt;code&gt;sys.stdout.softspace&lt;/code&gt; to 1. The space character wasn’t really printed until something else got printed on the same line. If the next &lt;code&gt;print&lt;/code&gt; statement printed a carriage return, &lt;code&gt;sys.stdout.softspace&lt;/code&gt; would be set to 0 and the space would never be printed. You probably never noticed the difference unless your application was sensitive to the presence or absence of trailing whitespace in &lt;code&gt;print&lt;/code&gt;-generated output.) In Python 3, the way to do this is to pass &lt;code&gt;end=&#39; &#39;&lt;/code&gt; as a keyword argument to the &lt;code&gt;print()&lt;/code&gt; function. The &lt;code&gt;end&lt;/code&gt; argument defaults to &lt;code&gt;&#39;\n&#39;&lt;/code&gt; (a carriage return), so overriding it will suppress the carriage return after printing the other arguments.
&lt;/li&gt;
&lt;li&gt;In Python 2, you could redirect the output to a pipe&amp;nbsp;—&amp;nbsp;like &lt;code&gt;sys.stderr&lt;/code&gt;&amp;nbsp;—&amp;nbsp;by using the &lt;code&gt;&amp;gt;&amp;gt;pipe_name&lt;/code&gt; syntax. In Python 3, the way to do this is to pass the pipe in the &lt;code&gt;file&lt;/code&gt; keyword argument. The &lt;code&gt;file&lt;/code&gt; argument defaults to &lt;code&gt;sys.stdout&lt;/code&gt; (standard out), so overriding it will output to a different pipe instead.
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;unicodeliteral&quot;&gt;
Unicode string literals&lt;/h2&gt;
Python 2 had two string types: &lt;dfn&gt;Unicode&lt;/dfn&gt; strings and non-Unicode strings. Python 3 has one string type: &lt;a href=&quot;https://www.blogger.com/strings.html#divingin&quot;&gt;Unicode strings&lt;/a&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;u&#39;PapayaWhip&#39;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;&#39;PapayaWhip&#39;&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;ur&#39;PapayaWhip\foo&#39;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;r&#39;PapayaWhip\foo&#39;&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Unicode string literals are simply converted into string literals, which, in Python 3, are always Unicode.
&lt;/li&gt;
&lt;li&gt;Unicode raw strings (in which Python does not auto-escape backslashes) are converted to raw strings. In Python 3, raw strings are always Unicode.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;unicode&quot;&gt;
&lt;code&gt;unicode()&lt;/code&gt; global function&lt;/h2&gt;
Python 2 had two global functions to coerce objects into strings: &lt;code&gt;unicode()&lt;/code&gt; to coerce them into Unicode strings, and &lt;code&gt;str()&lt;/code&gt; to coerce them into non-Unicode strings. Python 3 has only one string type, &lt;a href=&quot;https://www.blogger.com/strings.html#divingin&quot;&gt;Unicode strings&lt;/a&gt;, so the &lt;code&gt;str()&lt;/code&gt; function is all you need. (The &lt;code&gt;unicode()&lt;/code&gt; function no longer exists.)

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;unicode(anything)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;str(anything)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;long&quot;&gt;
&lt;code&gt;long&lt;/code&gt; data type&lt;/h2&gt;
Python 2 had separate &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;&lt;dfn&gt;long&lt;/dfn&gt;&lt;/code&gt; types for non-floating-point numbers. An &lt;code&gt;int&lt;/code&gt; could not be any larger than &lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=3524535260938031835#renames&quot;&gt;&lt;code&gt;sys.maxint&lt;/code&gt;&lt;/a&gt;, which varied by platform. Longs were defined by appending an &lt;code&gt;L&lt;/code&gt; to the end of the number, and they could be, well, longer than ints. In Python 3, &lt;a href=&quot;https://www.blogger.com/native-datatypes.html#numbers&quot;&gt;there is only one integer type&lt;/a&gt;, called &lt;code&gt;int&lt;/code&gt;, which mostly behaves like the &lt;code&gt;long&lt;/code&gt; type in Python 2. Since there are no longer two types, there is no need for special syntax to distinguish them.
&lt;br /&gt;
Further reading: &lt;a href=&quot;http://www.python.org/dev/peps/pep-0237/&quot;&gt;&lt;abbr&gt;PEP&lt;/abbr&gt; 237: Unifying Long Integers and Integers&lt;/a&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = 1000000000000L&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = 1000000000000&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = 0xFFFFFFFFFFFFL&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = 0xFFFFFFFFFFFF&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;long(x)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;int(x)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type(x) is long&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type(x) is int&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;isinstance(x, long)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;isinstance(x, int)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Base 10 long integer literals become base 10 integer literals.
&lt;/li&gt;
&lt;li&gt;Base 16 long integer literals become base 16 integer literals.
&lt;/li&gt;
&lt;li&gt;In Python 3, the old &lt;code&gt;long()&lt;/code&gt; function no longer exists, since longs don’t exist. To coerce a variable to an integer, use the &lt;code&gt;int()&lt;/code&gt; function.
&lt;/li&gt;
&lt;li&gt;To check whether a variable is an integer, get its type and compare it to &lt;code&gt;int&lt;/code&gt;, not &lt;code&gt;long&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;You can also use the &lt;code&gt;isinstance()&lt;/code&gt; function to check data types; again, use &lt;code&gt;int&lt;/code&gt;, not &lt;code&gt;long&lt;/code&gt;, to check for integers.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;ne&quot;&gt;
&amp;lt;&amp;gt; comparison&lt;/h2&gt;
Python 2 supported &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; as a synonym for &lt;code&gt;!=&lt;/code&gt;, the not-equals comparison operator. Python 3 supports the &lt;code&gt;!=&lt;/code&gt; operator, but not &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;if x &amp;lt;&amp;gt; y:&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;if x != y:&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;if x &amp;lt;&amp;gt; y &amp;lt;&amp;gt; z:&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;if x != y != z:&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;A simple comparison.
&lt;/li&gt;
&lt;li&gt;A more complex comparison between three values.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;has_key&quot;&gt;
&lt;code&gt;has_key()&lt;/code&gt; dictionary method&lt;/h2&gt;
In Python 2, dictionaries had a &lt;code&gt;&lt;dfn&gt;has_key&lt;/dfn&gt;()&lt;/code&gt; method to test whether the dictionary had a certain key. In Python 3, this method no longer exists. Instead, you need to use &lt;a href=&quot;https://www.blogger.com/native-datatypes.html#mixed-value-dictionaries&quot;&gt;the &lt;code&gt;in&lt;/code&gt; operator&lt;/a&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_dictionary.has_key(&#39;PapayaWhip&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;&#39;PapayaWhip&#39; in a_dictionary&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②&lt;/th&gt;
&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_dictionary.has_key(x) or a_dictionary.has_key(y)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x in a_dictionary or y in a_dictionary&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_dictionary.has_key(x or y)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;(x or y) in a_dictionary&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_dictionary.has_key(x + y)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;(x + y) in a_dictionary&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x + a_dictionary.has_key(y)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x + (y in a_dictionary)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;The simplest form.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;in&lt;/code&gt; operator takes precedence over the &lt;code&gt;or&lt;/code&gt; operator, so there is no need for parentheses around &lt;code&gt;x in a_dictionary&lt;/code&gt; or around &lt;code&gt;y in a_dictionary&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;On the other hand, you &lt;i&gt;do&lt;/i&gt; need parentheses around &lt;code&gt;x or y&lt;/code&gt; here, for the same reason&amp;nbsp;—&amp;nbsp;&lt;code&gt;in&lt;/code&gt; takes precedence over &lt;code&gt;or&lt;/code&gt;. (Note: this code is completely different from the previous line. Python interprets &lt;code&gt;x or y&lt;/code&gt; first, which results in either &lt;var&gt;x&lt;/var&gt; (if &lt;var&gt;x&lt;/var&gt; is &lt;a href=&quot;https://www.blogger.com/native-datatypes.html#booleans&quot;&gt;true in a boolean context&lt;/a&gt;) or &lt;var&gt;y&lt;/var&gt;. Then it takes that singular value and checks whether it is a key in &lt;var&gt;a_dictionary&lt;/var&gt;.)
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;+&lt;/code&gt; operator takes precedence over the &lt;code&gt;in&lt;/code&gt; operator, so this form technically doesn’t need parentheses around &lt;code&gt;x + y&lt;/code&gt;, but &lt;code&gt;2to3&lt;/code&gt; includes them anyway.
&lt;/li&gt;
&lt;li&gt;This form definitely needs parentheses around &lt;code&gt;y in a_dictionary&lt;/code&gt;, since the &lt;code&gt;+&lt;/code&gt; operator takes precedence over the &lt;code&gt;in&lt;/code&gt; operator.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;dict&quot;&gt;
Dictionary methods that return lists&lt;/h2&gt;
In Python 2, many dictionary methods returned lists. The most frequently used methods were &lt;code&gt;&lt;dfn&gt;keys&lt;/dfn&gt;()&lt;/code&gt;, &lt;code&gt;&lt;dfn&gt;items&lt;/dfn&gt;()&lt;/code&gt;, and &lt;code&gt;&lt;dfn&gt;values&lt;/dfn&gt;()&lt;/code&gt;. In Python 3, all of these methods return dynamic &lt;dfn&gt;views&lt;/dfn&gt;. In some contexts, this is not a problem. If the method’s return value is immediately passed to another function that iterates through the entire sequence, it makes no difference whether the actual type is a list or a view. In other contexts, it matters a great deal. If you were expecting a complete list with individually addressable elements, your code will choke, because views do not support indexing.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_dictionary.keys()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;list(a_dictionary.keys())&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_dictionary.items()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;list(a_dictionary.items())&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_dictionary.iterkeys()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;iter(a_dictionary.keys())&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in a_dictionary.iterkeys()]&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in a_dictionary.keys()]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;min(a_dictionary.keys())&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;2to3&lt;/code&gt; errs on the side of safety, converting the return value from &lt;code&gt;keys()&lt;/code&gt; to a static list with the &lt;code&gt;list()&lt;/code&gt; function. This will always work, but it will be less efficient than using a view. You should examine the converted code to see if a list is absolutely necessary, or if a view would do.
&lt;/li&gt;
&lt;li&gt;Another view-to-list conversion, with the &lt;code&gt;items()&lt;/code&gt; method. &lt;code&gt;2to3&lt;/code&gt; will do the same thing with the &lt;code&gt;values()&lt;/code&gt; method.
&lt;/li&gt;
&lt;li&gt;Python 3 does not support the &lt;code&gt;iterkeys()&lt;/code&gt; method anymore. Use &lt;code&gt;keys()&lt;/code&gt;, and if necessary, convert the view to an iterator with the &lt;code&gt;iter()&lt;/code&gt; function.
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;2to3&lt;/code&gt; recognizes when the &lt;code&gt;iterkeys()&lt;/code&gt; method is used inside a list comprehension, and converts it to the &lt;code&gt;keys()&lt;/code&gt; method (without wrapping it in an extra call to &lt;code&gt;iter()&lt;/code&gt;). This works because views are iterable.
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;2to3&lt;/code&gt; recognizes that the &lt;code&gt;keys()&lt;/code&gt; method is immediately passed to a function which iterates through an entire sequence, so there is no need to convert the return value to a list first. The &lt;code&gt;min()&lt;/code&gt; function will happily iterate through the view instead. This applies to &lt;code&gt;min()&lt;/code&gt;, &lt;code&gt;max()&lt;/code&gt;, &lt;code&gt;sum()&lt;/code&gt;, &lt;code&gt;list()&lt;/code&gt;, &lt;code&gt;tuple()&lt;/code&gt;, &lt;code&gt;set()&lt;/code&gt;, &lt;code&gt;sorted()&lt;/code&gt;, &lt;code&gt;any()&lt;/code&gt;, and &lt;code&gt;all()&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;imports&quot;&gt;
Modules that have been renamed or reorganized&lt;/h2&gt;
Several modules in the Python Standard Library have been renamed. Several other modules which are related to each other have been combined or reorganized to make their association more logical.

&lt;br /&gt;
&lt;h3 id=&quot;http&quot;&gt;
&lt;code&gt;http&lt;/code&gt;&lt;/h3&gt;
In Python 3, several related &lt;abbr&gt;HTTP&lt;/abbr&gt; modules have been combined into a single package, &lt;code&gt;http&lt;/code&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;httplib&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import http.client&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;Cookie&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import http.cookies&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;cookielib&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import http.cookiejar&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;import &lt;dfn&gt;BaseHTTPServer&lt;/dfn&gt;
import &lt;dfn&gt;SimpleHTTPServer&lt;/dfn&gt;
import &lt;dfn&gt;CGIHttpServer&lt;/dfn&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import http.server&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;http.client&lt;/code&gt; module implements a low-level library that can request &lt;abbr&gt;HTTP&lt;/abbr&gt; resources and interpret &lt;abbr&gt;HTTP&lt;/abbr&gt; responses.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;http.cookies&lt;/code&gt; module provides a Pythonic interface to browser cookies that are sent in a &lt;code&gt;Set-Cookie:&lt;/code&gt; &lt;abbr&gt;HTTP&lt;/abbr&gt; header.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;http.cookiejar&lt;/code&gt; module manipulates the actual files on disk that popular web browsers use to store cookies.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;http.server&lt;/code&gt; module provides a basic &lt;abbr&gt;HTTP&lt;/abbr&gt; server.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;urllib&quot;&gt;
&lt;code&gt;urllib&lt;/code&gt;&lt;/h3&gt;
Python 2 had a rat’s nest of overlapping modules to parse, encode, and fetch &lt;abbr&gt;URLs&lt;/abbr&gt;. In Python 3, these have all been refactored and combined in a single package, &lt;code&gt;urllib&lt;/code&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;urllib&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import urllib.request, urllib.parse, urllib.error&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;urllib2&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import urllib.request, urllib.error&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;urlparse&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import urllib.parse&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;robotparser&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import urllib.robotparser&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;from urllib import &lt;dfn&gt;FancyURLopener&lt;/dfn&gt;
from urllib import urlencode&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;from urllib.request import FancyURLopener
from urllib.parse import urlencode&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑥
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;from urllib2 import &lt;dfn&gt;Request&lt;/dfn&gt;
from urllib2 import &lt;dfn&gt;HTTPError&lt;/dfn&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;from urllib.request import Request
from urllib.error import HTTPError&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;The old &lt;code&gt;urllib&lt;/code&gt; module in Python 2 had a variety of functions, including &lt;code&gt;urlopen()&lt;/code&gt; for fetching data and &lt;code&gt;splittype()&lt;/code&gt;, &lt;code&gt;splithost()&lt;/code&gt;, and &lt;code&gt;splituser()&lt;/code&gt; for splitting a &lt;abbr&gt;URL&lt;/abbr&gt; into its constituent parts. These functions have been reorganized more logically within the new &lt;code&gt;urllib&lt;/code&gt; package. &lt;code&gt;2to3&lt;/code&gt; will also change all calls to these functions so they use the new naming scheme.
&lt;/li&gt;
&lt;li&gt;The old &lt;code&gt;urllib2&lt;/code&gt; module in Python 2 has been folded into the &lt;code&gt;urllib&lt;/code&gt; package in Python 3. All your &lt;code&gt;urllib2&lt;/code&gt; favorites&amp;nbsp;—&amp;nbsp;the &lt;code&gt;build_opener()&lt;/code&gt; method, &lt;code&gt;Request&lt;/code&gt; objects, and &lt;code&gt;HTTPBasicAuthHandler&lt;/code&gt; and friends&amp;nbsp;—&amp;nbsp;are still available.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;urllib.parse&lt;/code&gt; module in Python 3 contains all the parsing functions from the old &lt;code&gt;urlparse&lt;/code&gt; module in Python 2.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;urllib.robotparser&lt;/code&gt; module parses &lt;a href=&quot;http://www.robotstxt.org/&quot;&gt;&lt;code&gt;robots.txt&lt;/code&gt; files&lt;/a&gt;.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;FancyURLopener&lt;/code&gt; class, which handles &lt;abbr&gt;HTTP&lt;/abbr&gt; redirects and other status codes, is still available in the new &lt;code&gt;urllib.request&lt;/code&gt; module. The &lt;code&gt;urlencode()&lt;/code&gt; function has moved to &lt;code&gt;urllib.parse&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Request&lt;/code&gt; object is still available in &lt;code&gt;urllib.request&lt;/code&gt;, but constants like &lt;code&gt;HTTPError&lt;/code&gt; have been moved to &lt;code&gt;urllib.error&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;
Did I mention that &lt;code&gt;2to3&lt;/code&gt; will rewrite your function calls too? For example, if your Python 2 code imports the &lt;code&gt;urllib&lt;/code&gt; module and calls &lt;code&gt;urllib.urlopen()&lt;/code&gt; to fetch data, &lt;code&gt;2to3&lt;/code&gt; will fix both the import statement and the function call.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;import urllib
print urllib.urlopen(&#39;http://diveintopython3.org/&#39;).read()&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;import urllib.request, urllib.parse, urllib.error
print(urllib.request.urlopen(&#39;http://diveintopython3.org/&#39;).read())&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h3 id=&quot;dbm&quot;&gt;
&lt;code&gt;dbm&lt;/code&gt;&lt;/h3&gt;
All the various &lt;abbr&gt;DBM&lt;/abbr&gt; clones are now in a single package, &lt;code&gt;dbm&lt;/code&gt;. If you need a specific variant like &lt;abbr&gt;GNU&lt;/abbr&gt; &lt;abbr&gt;DBM&lt;/abbr&gt;, you can import the appropriate module within the &lt;code&gt;dbm&lt;/code&gt; package.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;dbm&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import dbm.ndbm&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;gdbm&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import dbm.gnu&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;dbhash&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import dbm.bsd&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;dumbdbm&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import dbm.dumb&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;import &lt;dfn&gt;anydbm&lt;/dfn&gt;
import whichdb&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import dbm&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h3 id=&quot;xmlrpc&quot;&gt;
&lt;code&gt;xmlrpc&lt;/code&gt;&lt;/h3&gt;
&lt;abbr&gt;XML-RPC&lt;/abbr&gt; is a lightweight method of performing remote &lt;abbr&gt;RPC&lt;/abbr&gt; calls over &lt;abbr&gt;HTTP&lt;/abbr&gt;. The &lt;abbr&gt;XML-RPC&lt;/abbr&gt; client library and several &lt;abbr&gt;XML-RPC&lt;/abbr&gt; server implementations are now combined in a single package, &lt;code&gt;xmlrpc&lt;/code&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;xmlrpclib&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import xmlrpc.client&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;import &lt;dfn&gt;DocXMLRPCServer&lt;/dfn&gt;
import &lt;dfn&gt;SimpleXMLRPCServer&lt;/dfn&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import xmlrpc.server&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h3 id=&quot;othermodules&quot;&gt;
Other modules&lt;/h3&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;try:
    import &lt;dfn&gt;cStringIO&lt;/dfn&gt; as &lt;dfn&gt;StringIO&lt;/dfn&gt;
except ImportError:
    import StringIO&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import io&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;try:
    import cPickle as pickle
except ImportError:
    import pickle&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import pickle&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;__builtin__&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import builtins&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;copy_reg&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import copyreg&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;Queue&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import queue&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑥
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;SocketServer&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import socketserver&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑦
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;ConfigParser&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import configparser&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑧
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import repr&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import reprlib&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑨
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import &lt;dfn&gt;commands&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import subprocess&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;ol&gt;
&lt;li&gt;A common idiom in Python 2 was to try to import &lt;code&gt;cStringIO as StringIO&lt;/code&gt;, and if that failed, to import &lt;code&gt;StringIO&lt;/code&gt; instead. Do not do this in Python 3; the &lt;code&gt;io&lt;/code&gt; module does it for you. It will find the fastest implementation available and use it automatically.
&lt;/li&gt;
&lt;li&gt;A similar idiom was used to import the fastest pickle implementation. Do not do this in Python 3; the &lt;code&gt;pickle&lt;/code&gt; module does it for you.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;builtins&lt;/code&gt; module contains the global functions, classes, and constants used throughout the Python language. Redefining a function in the &lt;code&gt;builtins&lt;/code&gt; module will redefine the global function everywhere. That is exactly as powerful and scary as it sounds.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;copyreg&lt;/code&gt; module adds pickle support for custom types defined in C.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;queue&lt;/code&gt; module implements a multi-producer, multi-consumer queue.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;socketserver&lt;/code&gt; module provides generic base classes for implementing different kinds of socket servers.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;configparser&lt;/code&gt; module parses &lt;abbr&gt;INI&lt;/abbr&gt;-style configuration files.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;reprlib&lt;/code&gt; module reimplements the built-in &lt;code&gt;repr()&lt;/code&gt; function, with additional controls on how long the representations can be before they are truncated.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;subprocess&lt;/code&gt; module allows you to spawn processes, connect to their pipes, and obtain their return codes.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;import&quot;&gt;
Relative imports within a package&lt;/h2&gt;
A package is a group of related modules that function as a single entity. In Python 2, when modules within a package need to reference each other, you use &lt;code&gt;import foo&lt;/code&gt; or &lt;code&gt;from foo import Bar&lt;/code&gt;. The Python 2 interpreter first searches within the current package to find &lt;code&gt;foo.py&lt;/code&gt;, and then moves on to the other directories in the Python search path (&lt;code&gt;sys.path&lt;/code&gt;). Python 3 works a bit differently. Instead of searching the current package, it goes directly to the Python search path. If you want one module within a package to import another module in the same package, you need to explicitly provide the relative path between the two modules.
&lt;br /&gt;
Suppose you had this package, with multiple files in the same directory:
&lt;br /&gt;
&lt;pre&gt;chardet/
|
+--__init__.py
|
+--constants.py
|
+--mbcharsetprober.py
|
+--universaldetector.py&lt;/pre&gt;
Now suppose that &lt;code&gt;universaldetector.py&lt;/code&gt; needs to import the entire &lt;code&gt;constants.py&lt;/code&gt; file and one class from &lt;code&gt;mbcharsetprober.py&lt;/code&gt;. How do you do it?

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;import constants&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;from . import constants&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;from mbcharsetprober import MultiByteCharSetProber&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;from .mbcharsetprober import MultiByteCharsetProber&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;When you need to import an entire module from elsewhere in your package, use the new &lt;code&gt;from . import&lt;/code&gt; syntax. The period is actually a relative path from this file (&lt;code&gt;universaldetector.py&lt;/code&gt;) to the file you want to import (&lt;code&gt;constants.py&lt;/code&gt;). In this case, they are in the same directory, thus the single period. You can also import from the parent directory (&lt;code&gt;from .. import anothermodule&lt;/code&gt;) or a subdirectory.
&lt;/li&gt;
&lt;li&gt;To import a specific class or function from another module directly into your module’s namespace, prefix the target module with a relative path, minus the trailing slash. In this case, &lt;code&gt;mbcharsetprober.py&lt;/code&gt; is in the same directory as &lt;code&gt;universaldetector.py&lt;/code&gt;, so the path is a single period. You can also import form the parent directory (&lt;code&gt;from ..anothermodule import AnotherClass&lt;/code&gt;) or a subdirectory.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;next&quot;&gt;
&lt;code&gt;next()&lt;/code&gt; iterator method&lt;/h2&gt;
In Python 2, iterators had a &lt;code&gt;&lt;dfn&gt;next&lt;/dfn&gt;()&lt;/code&gt; method which returned the next item in the sequence. That’s still true in Python 3, but there is now also &lt;a href=&quot;https://www.blogger.com/generators.html#generators&quot;&gt;a global &lt;code&gt;next()&lt;/code&gt; function&lt;/a&gt; that takes an iterator as an argument.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;anIterator.next()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;next(anIterator)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function_that_returns_an_iterator().next()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;next(a_function_that_returns_an_iterator())&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class A:
    def next(self):
        pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class A:
    def __next__(self):
        pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class A:
    def next(self, x, y):
        pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;next = 42
for an_iterator in a_sequence_of_iterators:
    an_iterator.next()&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;next = 42
for an_iterator in a_sequence_of_iterators:
    an_iterator.__next__()&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the simplest case, instead of calling an iterator’s &lt;code&gt;next()&lt;/code&gt; method, you now pass the iterator itself to the global &lt;code&gt;next()&lt;/code&gt; function.
&lt;/li&gt;
&lt;li&gt;If you have a function that returns an iterator, call the function and pass the result to the &lt;code&gt;next()&lt;/code&gt; function. (The &lt;code&gt;2to3&lt;/code&gt; script is smart enough to convert this properly.)
&lt;/li&gt;
&lt;li&gt;If you define your own class and mean to use it as an iterator, define the &lt;code&gt;__next__()&lt;/code&gt; special method.
&lt;/li&gt;
&lt;li&gt;If you define your own class and just happen to have a method named &lt;code&gt;next()&lt;/code&gt; that takes one or more arguments, &lt;code&gt;2to3&lt;/code&gt; will not touch it. This class can not be used as an iterator, because its &lt;code&gt;next()&lt;/code&gt; method takes arguments.
&lt;/li&gt;
&lt;li&gt;This one is a bit tricky. If you have a local variable named &lt;var&gt;next&lt;/var&gt;, then it takes precedence over the new global &lt;code&gt;next()&lt;/code&gt; function. In this case, you need to call the iterator’s special &lt;code&gt;__next__()&lt;/code&gt; method to get the next item in the sequence. (Alternatively, you could also refactor the code so the local variable wasn’t named &lt;var&gt;next&lt;/var&gt;, but &lt;code&gt;2to3&lt;/code&gt; will not do that for you automatically.)
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;filter&quot;&gt;
&lt;code&gt;filter()&lt;/code&gt; global function&lt;/h2&gt;
In Python 2, the &lt;code&gt;&lt;dfn&gt;filter&lt;/dfn&gt;()&lt;/code&gt; function returned a list, the result of filtering a sequence through a function that returned &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; for each item in the sequence. In Python 3, the &lt;code&gt;filter()&lt;/code&gt; function returns an iterator, not a list.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;filter(a_function, a_sequence)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;list(filter(a_function, a_sequence))&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;list(filter(a_function, a_sequence))&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;filter(None, a_sequence)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in a_sequence if i]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;for i in filter(None, a_sequence):&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in filter(a_function, a_sequence)]&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the most basic case, &lt;code&gt;2to3&lt;/code&gt; will wrap a call to &lt;code&gt;filter()&lt;/code&gt; with a call to &lt;code&gt;list()&lt;/code&gt;, which simply iterates through its argument and returns a real list.
&lt;/li&gt;
&lt;li&gt;However, if the call to &lt;code&gt;filter()&lt;/code&gt; is &lt;i&gt;already&lt;/i&gt; wrapped in &lt;code&gt;list()&lt;/code&gt;, &lt;code&gt;2to3&lt;/code&gt; will do nothing, since the fact that &lt;code&gt;filter()&lt;/code&gt; is returning an iterator is irrelevant.
&lt;/li&gt;
&lt;li&gt;For the special syntax of &lt;code&gt;filter(None, ...)&lt;/code&gt;, &lt;code&gt;2to3&lt;/code&gt; will transform the call into a semantically equivalent list comprehension.
&lt;/li&gt;
&lt;li&gt;In contexts like &lt;code&gt;for&lt;/code&gt; loops, which iterate through the entire sequence anyway, no changes are necessary.
&lt;/li&gt;
&lt;li&gt;Again, no changes are necessary, because the list comprehension will iterate through the entire sequence, and it can do that just as well if &lt;code&gt;filter()&lt;/code&gt; returns an iterator as if it returns a list.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;map&quot;&gt;
&lt;code&gt;map()&lt;/code&gt; global function&lt;/h2&gt;
In much the same way as &lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=3524535260938031835#filter&quot;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;, the &lt;code&gt;&lt;dfn&gt;map&lt;/dfn&gt;()&lt;/code&gt; function now returns an iterator. (In Python 2, it returned a list.)

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;map(a_function, &#39;PapayaWhip&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;list(map(a_function, &#39;PapayaWhip&#39;))&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;map(None, &#39;PapayaWhip&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;list(&#39;PapayaWhip&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;map(lambda x: x+1, range(42))&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[x+1 for x in range(42)]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;for i in map(a_function, a_sequence):&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in map(a_function, a_sequence)]&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;As with &lt;code&gt;filter()&lt;/code&gt;, in the most basic case, &lt;code&gt;2to3&lt;/code&gt; will wrap a call to &lt;code&gt;map()&lt;/code&gt; with a call to &lt;code&gt;list()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;For the special syntax of &lt;code&gt;map(None, ...)&lt;/code&gt;, the identity function, &lt;code&gt;2to3&lt;/code&gt; will convert it to an equivalent call to &lt;code&gt;list()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;If the first argument to &lt;code&gt;map()&lt;/code&gt; is a lambda function, &lt;code&gt;2to3&lt;/code&gt; will convert it to an equivalent list comprehension.
&lt;/li&gt;
&lt;li&gt;In contexts like &lt;code&gt;for&lt;/code&gt; loops, which iterate through the entire sequence anyway, no changes are necessary.
&lt;/li&gt;
&lt;li&gt;Again, no changes are necessary, because the list comprehension will iterate through the entire sequence, and it can do that just as well if &lt;code&gt;map()&lt;/code&gt; returns an iterator as if it returns a list.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;reduce&quot;&gt;
&lt;code&gt;reduce()&lt;/code&gt; global function&lt;/h2&gt;
In Python 3, the &lt;code&gt;&lt;dfn&gt;reduce&lt;/dfn&gt;()&lt;/code&gt; function has been removed from the global namespace and placed in the &lt;code&gt;functools&lt;/code&gt; module.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;reduce(a, b, c)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;from functools import reduce
reduce(a, b, c)&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;apply&quot;&gt;
&lt;code&gt;apply()&lt;/code&gt; global function&lt;/h2&gt;
Python 2 had a global function called &lt;code&gt;&lt;dfn&gt;apply&lt;/dfn&gt;()&lt;/code&gt;, which took a function &lt;var&gt;f&lt;/var&gt; and a list &lt;code&gt;[a, b, c]&lt;/code&gt; and returned &lt;code&gt;f(a, b, c)&lt;/code&gt;. You can accomplish the same thing by calling the function directly and passing it the list of arguments preceded by an asterisk. In Python 3, the &lt;code&gt;apply()&lt;/code&gt; function no longer exists; you must use the asterisk notation.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;apply(a_function, a_list_of_args)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function(*a_list_of_args)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;apply(a_function, a_list_of_args, a_dictionary_of_named_args)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function(*a_list_of_args, **a_dictionary_of_named_args)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;apply(a_function, a_list_of_args + z)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function(*a_list_of_args + z)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;apply(aModule.a_function, a_list_of_args)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;aModule.a_function(*a_list_of_args)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the simplest form, you can call a function with a list of arguments (an actual list like &lt;code&gt;[a, b, c]&lt;/code&gt;) by prepending the list with an asterisk (&lt;code&gt;*&lt;/code&gt;). This is exactly equivalent to the old &lt;code&gt;apply()&lt;/code&gt; function in Python 2.
&lt;/li&gt;
&lt;li&gt;In Python 2, the &lt;code&gt;apply()&lt;/code&gt; function could actually take three parameters: a function, a list of arguments, and a dictionary of named arguments. In Python 3, you can accomplish the same thing by prepending the list of arguments with an asterisk (&lt;code&gt;*&lt;/code&gt;) and the dictionary of named arguments with two asterisks (&lt;code&gt;**&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;+&lt;/code&gt; operator, used here for list concatenation, takes precedence over the &lt;code&gt;*&lt;/code&gt; operator, so there is no need for extra parentheses around &lt;code&gt;a_list_of_args + z&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;2to3&lt;/code&gt; script is smart enough to convert complex &lt;code&gt;apply()&lt;/code&gt; calls, including calling functions within imported modules.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;intern&quot;&gt;
&lt;code&gt;intern()&lt;/code&gt; global function&lt;/h2&gt;
In Python 2, you could call the &lt;code&gt;&lt;dfn&gt;intern&lt;/dfn&gt;()&lt;/code&gt; function on a string to intern it as a performance optimization. In Python 3, the &lt;code&gt;intern()&lt;/code&gt; function has been moved to the &lt;code&gt;sys&lt;/code&gt; module.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;intern(aString)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;sys.intern(aString)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;exec&quot;&gt;
&lt;code&gt;exec&lt;/code&gt; statement&lt;/h2&gt;
Just as &lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=3524535260938031835#print&quot;&gt;the &lt;code&gt;print&lt;/code&gt; statement&lt;/a&gt; became a function in Python 3, so too has the &lt;code&gt;&lt;dfn&gt;exec&lt;/dfn&gt;&lt;/code&gt; statement. The &lt;code&gt;exec()&lt;/code&gt; function takes a string which contains arbitrary Python code and executes it as if it were just another statement or expression. &lt;code&gt;exec()&lt;/code&gt; is like &lt;a href=&quot;https://www.blogger.com/advanced-iterators.html#eval&quot;&gt;&lt;code&gt;eval()&lt;/code&gt;&lt;/a&gt;, but even more powerful and evil. The &lt;code&gt;eval()&lt;/code&gt; function can only evaluate a single expression, but &lt;code&gt;exec()&lt;/code&gt; can execute multiple statements, imports, function declarations&amp;nbsp;—&amp;nbsp;essentially an entire Python program in a string.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;exec codeString&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;exec(codeString)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;exec codeString in a_global_namespace&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;exec(codeString, a_global_namespace)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;exec codeString in a_global_namespace, a_local_namespace&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;exec(codeString, a_global_namespace, a_local_namespace)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the simplest form, the &lt;code&gt;2to3&lt;/code&gt; script simply encloses the code-as-a-string in parentheses, since &lt;code&gt;exec()&lt;/code&gt; is now a function instead of a statement.
&lt;/li&gt;
&lt;li&gt;The old &lt;code&gt;exec&lt;/code&gt; statement could take a namespace, a private environment of globals in which the code-as-a-string would be executed. Python 3 can also do this; just pass the namespace as the second argument to the &lt;code&gt;exec()&lt;/code&gt; function.
&lt;/li&gt;
&lt;li&gt;Even fancier, the old &lt;code&gt;exec&lt;/code&gt; statement could also take a local namespace (like the variables defined within a function). In Python 3, the &lt;code&gt;exec()&lt;/code&gt; function can do that too.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;execfile&quot;&gt;
&lt;code&gt;execfile&lt;/code&gt; statement&lt;/h2&gt;
Like the old &lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=3524535260938031835#exec&quot;&gt;&lt;code&gt;exec&lt;/code&gt; statement&lt;/a&gt;, the old &lt;code&gt;execfile&lt;/code&gt; statement will execute strings as if they were Python code. Where &lt;code&gt;exec&lt;/code&gt; took a string, &lt;code&gt;execfile&lt;/code&gt; took a filename. In Python 3, the &lt;code&gt;execfile&lt;/code&gt; statement has been eliminated. If you really need to take a file of Python code and execute it (but you’re not willing to simply import it), you can accomplish the same thing by opening the file, reading its contents, calling the global &lt;code&gt;compile()&lt;/code&gt; function to force the Python interpreter to compile the code, and then call the new &lt;code&gt;exec()&lt;/code&gt; function.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;&lt;dfn&gt;execfile&lt;/dfn&gt;(&#39;a_filename&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;exec(compile(open(&#39;a_filename&#39;).read(), &#39;a_filename&#39;, &#39;exec&#39;))&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;repr&quot;&gt;
&lt;code&gt;repr&lt;/code&gt; literals (backticks)&lt;/h2&gt;
In Python 2, there was a special syntax of wrapping any object in &lt;dfn&gt;backticks&lt;/dfn&gt; (like &lt;code&gt;`x`&lt;/code&gt;) to get a representation of the object. In Python 3, this capability still exists, but you can no longer use backticks to get it. Instead, use the global &lt;code&gt;repr()&lt;/code&gt; function.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;`x`&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;repr(x)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;`&#39;PapayaWhip&#39; + `2``&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;repr(&#39;PapayaWhip&#39; + repr(2))&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Remember, &lt;var&gt;x&lt;/var&gt; can be anything&amp;nbsp;—&amp;nbsp;a class, a function, a module, a primitive data type, &lt;i class=&quot;baa&quot;&gt;&amp;amp;&lt;/i&gt;c. The &lt;code&gt;repr()&lt;/code&gt; function works on everything.
&lt;/li&gt;
&lt;li&gt;In Python 2, backticks could be nested, leading to this sort of confusing (but valid) expression. The &lt;code&gt;2to3&lt;/code&gt; tool is smart enough to convert this into nested calls to &lt;code&gt;repr()&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;except&quot;&gt;
&lt;code&gt;try...except&lt;/code&gt; statement&lt;/h2&gt;
The syntax for &lt;a href=&quot;https://www.blogger.com/your-first-python-program.html#exceptions&quot;&gt;catching &lt;dfn&gt;exceptions&lt;/dfn&gt;&lt;/a&gt; has changed slightly between Python 2 and Python 3.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;try:
    import mymodule
&lt;dfn&gt;except&lt;/dfn&gt; ImportError, e
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;try:
    import mymodule
except ImportError as e:
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;try:
    import mymodule
except (RuntimeError, ImportError), e
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;try:
    import mymodule
except (RuntimeError, ImportError) as e:
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;try:
    import mymodule
except ImportError:
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;try:
    import mymodule
except:
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Instead of a comma after the exception type, Python 3 uses a new keyword, &lt;code&gt;as&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;as&lt;/code&gt; keyword also works for catching multiple types of exceptions at once.
&lt;/li&gt;
&lt;li&gt;If you catch an exception but don’t actually care about accessing the &lt;dfn&gt;exception&lt;/dfn&gt; object itself, the syntax is identical between Python 2 and Python 3.
&lt;/li&gt;
&lt;li&gt;Similarly, if you use a fallback to catch &lt;i&gt;all&lt;/i&gt; exceptions, the syntax is identical.
&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote class=&quot;note&quot;&gt;
&lt;span class=&quot;u&quot;&gt;☞&lt;/span&gt;You should never use a fallback to catch &lt;i&gt;all&lt;/i&gt; exceptions when importing modules (or most other times). Doing so will catch things like &lt;code&gt;KeyboardInterrupt&lt;/code&gt; (if the user pressed &lt;kbd&gt;Ctrl-C&lt;/kbd&gt; to interrupt the program) and can make it more difficult to debug errors.
&lt;/blockquote&gt;
&lt;h2 id=&quot;raise&quot;&gt;
&lt;code&gt;raise&lt;/code&gt; statement&lt;/h2&gt;
The syntax for &lt;a href=&quot;https://www.blogger.com/your-first-python-program.html#exceptions&quot;&gt;raising your own exceptions&lt;/a&gt; has changed slightly between Python 2 and Python 3.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;&lt;dfn&gt;raise&lt;/dfn&gt; MyException&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;unchanged&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;raise MyException, &#39;error message&#39;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;raise MyException(&#39;error message&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;raise MyException, &#39;error message&#39;, a_traceback&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;raise MyException(&#39;error message&#39;).with_traceback(a_traceback)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;raise &#39;error message&#39;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;unsupported&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the simplest form, raising an exception without a custom error message, the syntax is unchanged.
&lt;/li&gt;
&lt;li&gt;The change becomes noticeable when you want to raise an exception with a custom error message. Python 2 separated the exception class and the message with a comma; Python 3 passes the error message as a parameter.
&lt;/li&gt;
&lt;li&gt;Python 2 supported a more complex syntax to raise an exception with a custom traceback (stack trace). You can do this in Python 3 as well, but the syntax is quite different.
&lt;/li&gt;
&lt;li&gt;In Python 2, you could raise an exception with no exception class, just an error message. In Python 3, this is no longer possible. &lt;code&gt;2to3&lt;/code&gt; will warn you that it was unable to fix this automatically.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;throw&quot;&gt;
&lt;code&gt;throw&lt;/code&gt; method on generators&lt;/h2&gt;
In Python 2, generators have a &lt;code&gt;&lt;dfn&gt;throw&lt;/dfn&gt;()&lt;/code&gt; method. Calling &lt;code&gt;a_generator.throw()&lt;/code&gt; raises an exception at the point where the generator was paused, then returns the next value yielded by the generator function. In Python 3, this functionality is still available, but the syntax is slightly different.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_generator.throw(MyException)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_generator.throw(MyException, &#39;error message&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_generator.throw(MyException(&#39;error message&#39;))&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_generator.throw(&#39;error message&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;unsupported&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the simplest form, a generator throws an exception without a custom error message. In this case, the syntax has not changed between Python 2 and Python 3.
&lt;/li&gt;
&lt;li&gt;If the generator throws an exception &lt;i&gt;with&lt;/i&gt; a custom error message, you need to pass the error string to the exception when you create it.
&lt;/li&gt;
&lt;li&gt;Python 2 also supported throwing an exception with &lt;i&gt;only&lt;/i&gt; a custom error message. Python 3 does not support this, and the &lt;code&gt;2to3&lt;/code&gt; script will display a warning telling you that you will need to fix this code manually.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;xrange&quot;&gt;
&lt;code&gt;xrange()&lt;/code&gt; global function&lt;/h2&gt;
In Python 2, there were two ways to get a range of numbers: &lt;code&gt;&lt;dfn&gt;range&lt;/dfn&gt;()&lt;/code&gt;, which returned a list, and &lt;code&gt;&lt;dfn&gt;xrange&lt;/dfn&gt;()&lt;/code&gt;, which returned an iterator. In Python 3, &lt;code&gt;range()&lt;/code&gt; returns an iterator, and &lt;code&gt;xrange()&lt;/code&gt; doesn’t exist.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;xrange(10)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;range(10)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_list = range(10)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_list = list(range(10))&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in xrange(10)]&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in range(10)]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;for i in range(10):&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;sum(range(10))&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the simplest case, the &lt;code&gt;2to3&lt;/code&gt; script will simply convert &lt;code&gt;xrange()&lt;/code&gt; to &lt;code&gt;range()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;If your Python 2 code used &lt;code&gt;range()&lt;/code&gt;, the &lt;code&gt;2to3&lt;/code&gt; script does not know whether you needed a list, or whether an iterator would do. It errs on the side of caution and coerces the return value into a list by calling the &lt;code&gt;list()&lt;/code&gt; function.
&lt;/li&gt;
&lt;li&gt;If the &lt;code&gt;xrange()&lt;/code&gt; function was inside a list comprehension, the &lt;code&gt;2to3&lt;/code&gt; script is clever enough &lt;i&gt;not&lt;/i&gt; to wrap the &lt;code&gt;range()&lt;/code&gt; function with a call to &lt;code&gt;list()&lt;/code&gt;. The list comprehension will work just fine with the iterator that the &lt;code&gt;range()&lt;/code&gt; function returns.
&lt;/li&gt;
&lt;li&gt;Similarly, a &lt;code&gt;for&lt;/code&gt; loop will work just fine with an iterator, so there is no need to change anything here.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;sum()&lt;/code&gt; function will also work with an iterator, so &lt;code&gt;2to3&lt;/code&gt; makes no changes here either. Like &lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=3524535260938031835#dict&quot;&gt;dictionary methods that return views instead of lists&lt;/a&gt;, this applies to &lt;code&gt;min()&lt;/code&gt;, &lt;code&gt;max()&lt;/code&gt;, &lt;code&gt;sum()&lt;/code&gt;, &lt;code&gt;list()&lt;/code&gt;, &lt;code&gt;tuple()&lt;/code&gt;, &lt;code&gt;set()&lt;/code&gt;, &lt;code&gt;sorted()&lt;/code&gt;, &lt;code&gt;any()&lt;/code&gt;, and &lt;code&gt;all()&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;raw_input&quot;&gt;
&lt;code&gt;raw_input()&lt;/code&gt; and &lt;code&gt;input()&lt;/code&gt; global functions&lt;/h2&gt;
Python 2 had two global functions for asking the user for input on the command line. The first, called &lt;code&gt;input()&lt;/code&gt;, expected the user to enter a Python expression (and returned the result). The second, called &lt;code&gt;&lt;dfn&gt;raw_input&lt;/dfn&gt;()&lt;/code&gt;, just returned whatever the user typed. This was wildly confusing for beginners and widely regarded as a “wart” in the language. Python 3 excises this wart by renaming &lt;code&gt;raw_input()&lt;/code&gt; to &lt;code&gt;input()&lt;/code&gt;, so it works the way everyone naively expects it to work.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;raw_input()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;input()&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;raw_input(&#39;prompt&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;input(&#39;prompt&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;input()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;eval(input())&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the simplest form, &lt;code&gt;raw_input()&lt;/code&gt; becomes &lt;code&gt;input()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;In Python 2, the &lt;code&gt;raw_input()&lt;/code&gt; function could take a prompt as a parameter. This has been retained in Python 3.
&lt;/li&gt;
&lt;li&gt;If you actually need to ask the user for a Python expression to evaluate, use the &lt;code&gt;input()&lt;/code&gt; function and pass the result to &lt;code&gt;eval()&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;funcattrs&quot;&gt;
&lt;code&gt;func_*&lt;/code&gt; function attributes&lt;/h2&gt;
In Python 2, code within functions can access special attributes about the function itself. In Python 3, these special function attributes have been renamed for consistency with other attributes.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.&lt;dfn&gt;func_name&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.__name__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.&lt;dfn&gt;func_doc&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.__doc__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.&lt;dfn&gt;func_defaults&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.__defaults__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.&lt;dfn&gt;func_dict&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.__dict__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑤
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.&lt;dfn&gt;func_closure&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.__closure__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑥
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.&lt;dfn&gt;func_globals&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.__globals__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;⑦
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.&lt;dfn&gt;func_code&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function.__code__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;__name__&lt;/code&gt; attribute (previously &lt;code&gt;func_name&lt;/code&gt;) contains the function’s name.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;__doc__&lt;/code&gt; attribute (previously &lt;code&gt;func_doc&lt;/code&gt;) contains the &lt;i&gt;docstring&lt;/i&gt; that you defined in the function’s source code.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;__defaults__&lt;/code&gt; attribute (previously &lt;code&gt;func_defaults&lt;/code&gt;) is a tuple containing default argument values for those arguments that have default values.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;__dict__&lt;/code&gt; attribute (previously &lt;code&gt;func_dict&lt;/code&gt;) is the namespace supporting arbitrary function attributes.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;__closure__&lt;/code&gt; attribute (previously &lt;code&gt;func_closure&lt;/code&gt;) is a tuple of cells that contain bindings for the function’s free variables.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;__globals__&lt;/code&gt; attribute (previously &lt;code&gt;func_globals&lt;/code&gt;) is a reference to the global namespace of the module in which the function was defined.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;__code__&lt;/code&gt; attribute (previously &lt;code&gt;func_code&lt;/code&gt;) is a code object representing the compiled function body.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;xreadlines&quot;&gt;
&lt;code&gt;xreadlines()&lt;/code&gt; I/O method&lt;/h2&gt;
In Python 2, file objects had an &lt;code&gt;&lt;dfn&gt;xreadlines&lt;/dfn&gt;()&lt;/code&gt; method which returned an iterator that would read the file one line at a time. This was useful in &lt;code&gt;for&lt;/code&gt; loops, among other places. In fact, it was so useful, later versions of Python 2 added the capability to file objects themselves.

&lt;br /&gt;
In Python 3, the &lt;code&gt;xreadlines()&lt;/code&gt; method no longer exists. &lt;code&gt;2to3&lt;/code&gt; can fix the simple cases, but some edge cases will require manual intervention.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;for line in a_file.xreadlines():&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;for line in a_file:&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;for line in a_file.xreadlines(5):&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change (broken)&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;If you used to call &lt;code&gt;xreadlines()&lt;/code&gt; with no arguments, &lt;code&gt;2to3&lt;/code&gt; will convert it to just the file object. In Python 3, this will accomplish the same thing: read the file one line at a time and execute the body of the &lt;code&gt;for&lt;/code&gt; loop.
&lt;/li&gt;
&lt;li&gt;If you used to call &lt;code&gt;xreadlines()&lt;/code&gt; with an argument (the number of lines to read at a time), &lt;code&gt;2to3&lt;/code&gt; will not fix it, and your code will fail with an &lt;code&gt;AttributeError: &#39;_io.TextIOWrapper&#39; object has no attribute &#39;xreadlines&#39;&lt;/code&gt;. You can manually change &lt;code&gt;xreadlines()&lt;/code&gt; to &lt;code&gt;readlines()&lt;/code&gt; to get it to work in Python 3. (The &lt;code&gt;readlines()&lt;/code&gt; method now returns an iterator, so it is just as efficient as &lt;code&gt;xreadlines()&lt;/code&gt; was in Python 2.)
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;c&quot;&gt;
&lt;span style=&quot;font-size: 56px; line-height: 0.88;&quot;&gt;☃&lt;/span&gt;

&lt;/div&gt;
&lt;h2 id=&quot;tuple_params&quot;&gt;
&lt;code&gt;lambda&lt;/code&gt; functions that take a tuple instead of multiple parameters&lt;/h2&gt;
In Python 2, you could define anonymous &lt;code&gt;&lt;dfn&gt;lambda&lt;/dfn&gt;&lt;/code&gt; functions which took multiple parameters by defining the function as taking a tuple with a specific number of items. In effect, Python 2 would “unpack” the tuple into named arguments, which you could then reference (by name) within the &lt;code&gt;lambda&lt;/code&gt; function. In Python 3, you can still pass a tuple to a &lt;code&gt;lambda&lt;/code&gt; function, but the Python interpreter will not unpack the tuple into named arguments. Instead, you will need to reference each argument by its positional index.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;lambda (x,): x + f(x)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;lambda x1: x1[0] + f(x1[0])&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;lambda (x, y): x + f(y)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;lambda x_y: x_y[0] + f(x_y[1])&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;lambda (x, (y, z)): x + y + z&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;lambda x, y, z: x + y + z&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;unchanged&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;If you had defined a &lt;code&gt;lambda&lt;/code&gt; function that took a tuple of one item, in Python 3 that would become a &lt;code&gt;lambda&lt;/code&gt; with references to &lt;var&gt;x1[0]&lt;/var&gt;. The name &lt;var&gt;x1&lt;/var&gt; is autogenerated by the &lt;code&gt;2to3&lt;/code&gt; script, based on the named arguments in the original tuple.
&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;lambda&lt;/code&gt; function with a two-item tuple &lt;var&gt;(x, y)&lt;/var&gt; gets converted to &lt;var&gt;x_y&lt;/var&gt; with positional arguments &lt;var&gt;x_y[0]&lt;/var&gt; and &lt;var&gt;x_y[1]&lt;/var&gt;.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;2to3&lt;/code&gt; script can even handle &lt;code&gt;lambda&lt;/code&gt; functions with nested tuples of named arguments. The resulting Python 3 code is a bit unreadable, but it works the same as the old code did in Python 2.
&lt;/li&gt;
&lt;li&gt;You can define &lt;code&gt;lambda&lt;/code&gt; functions that take multiple arguments. Without parentheses around the arguments, Python 2 just treats it as a &lt;code&gt;lambda&lt;/code&gt; function with multiple arguments; within the &lt;code&gt;lambda&lt;/code&gt; function, you simply reference the arguments by name, just like any other function. This syntax still works in Python 3.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;methodattrs&quot;&gt;
Special method attributes&lt;/h2&gt;
In Python 2, class methods can reference the class object in which they are defined, as well as the method object itself.  &lt;code&gt;im_self&lt;/code&gt; is the class instance object; &lt;code&gt;im_func&lt;/code&gt; is the function object; &lt;code&gt;im_class&lt;/code&gt; is the class of &lt;code&gt;im_self&lt;/code&gt;. In Python 3, these special method attributes have been renamed to follow the naming conventions of other attributes.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;aClassInstance.aClassMethod.&lt;dfn&gt;im_func&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;aClassInstance.aClassMethod.__func__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;aClassInstance.aClassMethod.&lt;dfn&gt;im_self&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;aClassInstance.aClassMethod.__self__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;aClassInstance.aClassMethod.&lt;dfn&gt;im_class&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;aClassInstance.aClassMethod.__self__.__class__&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;nonzero&quot;&gt;
&lt;code&gt;__nonzero__&lt;/code&gt; special method&lt;/h2&gt;
In Python 2, you could build your own classes that could be used in a boolean context. For example, you could instantiate the class and then use the instance in an &lt;code&gt;if&lt;/code&gt; statement. To do this, you defined a special &lt;code&gt;__nonzero__()&lt;/code&gt; method which returned &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;, and it was called whenever the instance was used in a boolean context. In Python 3, you can still do this, but the name of the method has changed to &lt;code&gt;__bool__()&lt;/code&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class A:
    def &lt;dfn&gt;__nonzero__&lt;/dfn&gt;(self):
        pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class A:
    def &lt;dfn&gt;__bool__&lt;/dfn&gt;(self):
        pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class A:
    def __nonzero__(self, x, y):
        pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Instead of &lt;code&gt;__nonzero__()&lt;/code&gt;, Python 3 calls the &lt;code&gt;__bool__()&lt;/code&gt; method when evaluating an instance in a boolean context.
&lt;/li&gt;
&lt;li&gt;However, if you have a &lt;code&gt;__nonzero__()&lt;/code&gt; method that takes arguments, the &lt;code&gt;2to3&lt;/code&gt; tool will assume that you were using it for some other purpose, and it will not make any changes.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;numliterals&quot;&gt;
Octal literals&lt;/h2&gt;
The syntax for defining base 8 (&lt;dfn&gt;octal&lt;/dfn&gt;) numbers has changed slightly between Python 2 and Python 3.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = 0755&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = 0o755&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;renames&quot;&gt;
&lt;code&gt;sys.maxint&lt;/code&gt;&lt;/h2&gt;
Due to the &lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=3524535260938031835#long&quot;&gt;integration of the &lt;code&gt;long&lt;/code&gt; and &lt;code&gt;int&lt;/code&gt; types&lt;/a&gt;, the &lt;code&gt;sys.maxint&lt;/code&gt; constant is no longer accurate. Because the value may still be useful in determining platform-specific capabilities, it has been retained but renamed as &lt;code&gt;sys.maxsize&lt;/code&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;from sys import &lt;dfn&gt;maxint&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;from sys import &lt;dfn&gt;maxsize&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function(&lt;dfn&gt;sys.maxint&lt;/dfn&gt;)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a_function(&lt;dfn&gt;sys.maxsize&lt;/dfn&gt;)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;maxint&lt;/code&gt; becomes &lt;code&gt;maxsize&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Any usage of &lt;code&gt;sys.maxint&lt;/code&gt; becomes &lt;code&gt;sys.maxsize&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;callable&quot;&gt;
&lt;code&gt;callable()&lt;/code&gt; global function&lt;/h2&gt;
In Python 2, you could check whether an object was callable (like a function) with the global &lt;code&gt;&lt;dfn&gt;callable&lt;/dfn&gt;()&lt;/code&gt; function. In Python 3, this global function has been eliminated. To check whether an object is callable, check for the existence of the &lt;code&gt;__call__()&lt;/code&gt; special method.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;callable(anything)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;hasattr(anything, &#39;__call__&#39;)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;zip&quot;&gt;
&lt;code&gt;zip()&lt;/code&gt; global function&lt;/h2&gt;
In Python 2, the global &lt;code&gt;&lt;dfn&gt;zip&lt;/dfn&gt;()&lt;/code&gt; function took any number of sequences and returned a list of tuples. The first tuple contained the first item from each sequence; the second tuple contained the second item from each sequence; and so on. In Python 3, &lt;code&gt;zip()&lt;/code&gt; returns an iterator instead of a list.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;zip(a, b, c)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;list(zip(a, b, c))&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;d.join(zip(a, b, c))&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;no change&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;In the simplest form, you can get the old behavior of the &lt;code&gt;zip()&lt;/code&gt; function by wrapping the return value in a call to &lt;code&gt;list()&lt;/code&gt;, which will run through the iterator that &lt;code&gt;zip()&lt;/code&gt; returns and return a real list of the results.
&lt;/li&gt;
&lt;li&gt;In contexts that already iterate through all the items of a sequence (such as this call to the &lt;code&gt;join()&lt;/code&gt; method), the iterator that &lt;code&gt;zip()&lt;/code&gt; returns will work just fine. The &lt;code&gt;2to3&lt;/code&gt; script is smart enough to detect these cases and make no change to your code.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;standarderror&quot;&gt;
&lt;code&gt;StandardError&lt;/code&gt; exception&lt;/h2&gt;
In Python 2, &lt;code&gt;&lt;dfn&gt;StandardError&lt;/dfn&gt;&lt;/code&gt; was the base class for all built-in exceptions other than &lt;code&gt;StopIteration&lt;/code&gt;, &lt;code&gt;GeneratorExit&lt;/code&gt;, &lt;code&gt;KeyboardInterrupt&lt;/code&gt;, and &lt;code&gt;SystemExit&lt;/code&gt;. In Python 3, &lt;code&gt;StandardError&lt;/code&gt; has been eliminated; use &lt;code&gt;Exception&lt;/code&gt; instead.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = StandardError()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = Exception()&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = StandardError(a, b, c)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = Exception(a, b, c)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;types&quot;&gt;
&lt;code&gt;types&lt;/code&gt; module constants&lt;/h2&gt;
The &lt;code&gt;types&lt;/code&gt; module contains a variety of constants to help you determine the type of an object. In Python 2, it contained constants for all primitive types like &lt;code&gt;dict&lt;/code&gt; and &lt;code&gt;int&lt;/code&gt;. In Python 3, these constants have been eliminated; just use the primitive type name instead.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;UnicodeType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;str&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;StringType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;bytes&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;DictType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;dict&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;IntType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;int&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;LongType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;int&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;ListType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;list&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;NoneType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type(None)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;BooleanType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;bool&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;BufferType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;memoryview&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;ClassType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;ComplexType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;complex&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;EllipsisType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type(Ellipsis)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;FloatType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;float&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;ObjectType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;object&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;NotImplementedType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type(NotImplemented)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;SliceType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;slice&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;TupleType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;tuple&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;TypeType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;types.&lt;dfn&gt;XRangeType&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;range&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;note&quot;&gt;
&lt;span class=&quot;u&quot;&gt;☞&lt;/span&gt;&lt;code&gt;types.StringType&lt;/code&gt; gets mapped to &lt;code&gt;bytes&lt;/code&gt; instead of &lt;code&gt;str&lt;/code&gt; because a Python 2 “string” (not a Unicode string, just a regular string) is really just a sequence of bytes in a particular character encoding.
&lt;/blockquote&gt;
&lt;h2 id=&quot;isinstance&quot;&gt;
&lt;code&gt;isinstance()&lt;/code&gt; global function&lt;/h2&gt;
The &lt;code&gt;isinstance()&lt;/code&gt; function checks whether an object is an instance of a particular class or type. In Python 2, you could pass a tuple of types, and &lt;code&gt;isinstance()&lt;/code&gt; would return &lt;code&gt;True&lt;/code&gt; if the object was any of those types. In Python 3, you can still do this, but passing the same type twice is deprecated.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;isinstance(x, (int, float, int))&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;isinstance(x, (int, float))&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;basestring&quot;&gt;
&lt;code&gt;basestring&lt;/code&gt; datatype&lt;/h2&gt;
Python 2 had two string types: Unicode and non-Unicode. But there was also another type, &lt;code&gt;&lt;dfn&gt;basestring&lt;/dfn&gt;&lt;/code&gt;. It was an abstract type, a superclass for both the &lt;code&gt;str&lt;/code&gt; and &lt;code&gt;unicode&lt;/code&gt; types. It couldn’t be called or instantiated directly, but you could pass it to the global &lt;code&gt;isinstance()&lt;/code&gt; function to check whether an object was either a Unicode or non-Unicode string. In Python 3, there is only one string type, so &lt;code&gt;basestring&lt;/code&gt; has no reason to exist.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;isinstance(x, basestring)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;isinstance(x, str)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;itertools&quot;&gt;
&lt;code&gt;itertools&lt;/code&gt; module&lt;/h2&gt;
Python 2.3 introduced the &lt;code&gt;itertools&lt;/code&gt; module, which defined variants of the global &lt;code&gt;zip()&lt;/code&gt;, &lt;code&gt;map()&lt;/code&gt;, and &lt;code&gt;filter()&lt;/code&gt; functions that returned iterators instead of lists. In Python 3, those global functions return iterators, so those functions in the &lt;code&gt;itertools&lt;/code&gt; module have been eliminated. (There are still &lt;a href=&quot;https://www.blogger.com/advanced-iterators.html#more-itertools&quot;&gt;lots of useful functions in the &lt;code&gt;itertools&lt;/code&gt; module&lt;/a&gt;, just not these.)

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;itertools.&lt;dfn&gt;izip&lt;/dfn&gt;(a, b)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;zip(a, b)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;itertools.&lt;dfn&gt;imap&lt;/dfn&gt;(a, b)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;map(a, b)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;itertools.&lt;dfn&gt;ifilter&lt;/dfn&gt;(a, b)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;filter(a, b)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;④
&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;from itertools import imap, izip, foo&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;from itertools import foo&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Instead of &lt;code&gt;itertools.izip()&lt;/code&gt;, just use the global &lt;code&gt;zip()&lt;/code&gt; function.
&lt;/li&gt;
&lt;li&gt;Instead of &lt;code&gt;itertools.imap()&lt;/code&gt;, just use &lt;code&gt;map()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;itertools.ifilter()&lt;/code&gt; becomes &lt;code&gt;filter()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;itertools&lt;/code&gt; module still exists in Python 3, it just doesn’t have the functions that have migrated to the global namespace. The &lt;code&gt;2to3&lt;/code&gt; script is smart enough to remove the specific imports that no longer exist, while leaving other imports intact.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;sys_exc&quot;&gt;
&lt;code&gt;sys.exc_type&lt;/code&gt;, &lt;code&gt;sys.exc_value&lt;/code&gt;, &lt;code&gt;sys.exc_traceback&lt;/code&gt;&lt;/h2&gt;
Python 2 had three variables in the &lt;code&gt;sys&lt;/code&gt; module that you could access while an exception was being handled: &lt;code&gt;sys.exc_type&lt;/code&gt;, &lt;code&gt;sys.exc_value&lt;/code&gt;, &lt;code&gt;sys.exc_traceback&lt;/code&gt;. (Actually, these date all the way back to Python 1.)  Ever since Python 1.5, these variables have been deprecated in favor of &lt;code&gt;sys.exc_info()&lt;/code&gt;, which is a function that returns a tuple containing those three values. In Python 3, these individual variables have finally gone away; you must use the &lt;code&gt;sys.exc_info()&lt;/code&gt; function.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;&lt;dfn&gt;sys.exc_type&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;sys.exc_info()[0]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;&lt;dfn&gt;sys.exc_value&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;sys.exc_info()[1]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;&lt;dfn&gt;sys.exc_traceback&lt;/dfn&gt;&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;sys.exc_info()[2]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;paren&quot;&gt;
List comprehensions over tuples&lt;/h2&gt;
In Python 2, if you wanted to code a list comprehension that iterated over a tuple, you did not need to put parentheses around the tuple values. In Python 3, explicit parentheses are required.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in 1, 2]&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;[i for i in (1, 2)]&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;getcwdu&quot;&gt;
&lt;code&gt;os.getcwdu()&lt;/code&gt; function&lt;/h2&gt;
Python 2 had a function named &lt;code&gt;os.getcwd()&lt;/code&gt;, which returned the current working directory as a (non-Unicode) string. Because modern file systems can handle directory names in any character encoding, Python 2.3 introduced &lt;code&gt;os.getcwdu()&lt;/code&gt;. The &lt;code&gt;os.getcwdu()&lt;/code&gt; function returned the current working directory as a Unicode string. In Python 3, there is &lt;a href=&quot;https://www.blogger.com/strings.html#divingin&quot;&gt;only one string type (Unicode)&lt;/a&gt;, so &lt;code&gt;os.getcwd()&lt;/code&gt; is all you need.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;&lt;dfn&gt;os.getcwdu&lt;/dfn&gt;()&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;os.getcwd()&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h2 id=&quot;metaclass&quot;&gt;
Metaclasses&lt;/h2&gt;
In Python 2, you could create metaclasses either by defining the &lt;code&gt;metaclass&lt;/code&gt; argument in the class declaration, or by defining a special class-level &lt;code&gt;&lt;dfn&gt;__metaclass__&lt;/dfn&gt;&lt;/code&gt; attribute. In Python 3, the class-level attribute has been eliminated.

&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Python 2
&lt;/th&gt;&lt;th&gt;Python 3
&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;①
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class C(metaclass=PapayaMeta):
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;i&gt;unchanged&lt;/i&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;②
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class Whip:
    __metaclass__ = PapayaMeta&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class Whip(metaclass=PapayaMeta):
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;③
&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class C(Whipper, Beater):
    __metaclass__ = PapayaMeta&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;class C(Whipper, Beater, metaclass=PapayaMeta):
    pass&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Declaring the metaclass in the class declaration worked in Python 2, and it still works the same in Python 3.
&lt;/li&gt;
&lt;li&gt;Declaring the metaclass in a class attribute worked in Python 2, but doesn’t work in Python 3.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;2to3&lt;/code&gt; script is smart enough to construct a valid class declaration, even if the class is inherited from one or more base classes.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;nitpick&quot;&gt;
Matters of style&lt;/h2&gt;
The rest of the “fixes” listed here aren’t really fixes per se. That is, the things they change are matters of style, not substance. They work just as well in Python 3 as they do in Python 2, but the developers of Python have a vested interest in making Python code as uniform as possible. To that end, there is an &lt;a href=&quot;http://www.python.org/dev/peps/pep-0008/&quot;&gt;official Python style guide&lt;/a&gt; which outlines&amp;nbsp;—&amp;nbsp;in excruciating detail&amp;nbsp;—&amp;nbsp;all sorts of nitpicky details that you almost certainly don’t care about. And given that &lt;code&gt;2to3&lt;/code&gt; provides such a great infrastructure for converting Python code from one thing to another, the authors took it upon themselves to add a few optional features to improve the readability of your Python programs.

&lt;br /&gt;
&lt;h3 id=&quot;set_literal&quot;&gt;
&lt;code&gt;set()&lt;/code&gt; literals (explicit)&lt;/h3&gt;
In Python 2, the only way to define a literal set in your code was to call &lt;code&gt;set(a_sequence)&lt;/code&gt;. This still works in Python 3, but a clearer way of doing it is to use the new set literal notation: curly braces. This works for everything except empty sets, because dictionaries also use curly braces, so &lt;a href=&quot;https://www.blogger.com/native-datatypes.html#emptyset&quot;&gt;&lt;code&gt;{}&lt;/code&gt; is an empty dictionary, not an empty set&lt;/a&gt;.

&lt;br /&gt;
&lt;blockquote class=&quot;note&quot;&gt;
&lt;span class=&quot;u&quot;&gt;☞&lt;/span&gt;The &lt;code&gt;2to3&lt;/code&gt; script will not fix &lt;code&gt;set()&lt;/code&gt; literals by default. To enable this fix, specify &lt;kbd&gt;-f set_literal&lt;/kbd&gt; on the command line when you call &lt;code&gt;2to3&lt;/code&gt;.
&lt;/blockquote&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Before
&lt;/th&gt;&lt;th&gt;After

&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;set([1, 2, 3])&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;{1, 2, 3}&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;set((1, 2, 3))&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;{1, 2, 3}&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;set([i for i in a_sequence])&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;{i for i in a_sequence}&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 id=&quot;buffer&quot;&gt;
&lt;code&gt;buffer()&lt;/code&gt; global function (explicit)&lt;/h3&gt;
Python objects implemented in C can export a “buffer interface,” which allows other Python code to directly read and write a block of memory. (That is exactly as powerful and scary as it sounds.)  In Python 3, &lt;code&gt;buffer()&lt;/code&gt; has been renamed to &lt;code&gt;memoryview()&lt;/code&gt;. (It’s a little more complicated than that, but you can almost certainly ignore the differences.)

&lt;br /&gt;
&lt;blockquote class=&quot;note&quot;&gt;
&lt;span class=&quot;u&quot;&gt;☞&lt;/span&gt;The &lt;code&gt;2to3&lt;/code&gt; script will not fix the &lt;code&gt;buffer()&lt;/code&gt; function by default. To enable this fix, specify &lt;kbd&gt;-f buffer&lt;/kbd&gt; on the command line when you call &lt;code&gt;2to3&lt;/code&gt;.
&lt;/blockquote&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Before
&lt;/th&gt;&lt;th&gt;After

&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = &lt;dfn&gt;buffer&lt;/dfn&gt;(y)&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;x = &lt;dfn&gt;memoryview&lt;/dfn&gt;(y)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 id=&quot;wscomma&quot;&gt;
Whitespace around commas (explicit)&lt;/h3&gt;
Despite being draconian about whitespace for indenting and outdenting, Python is actually quite liberal about whitespace in other areas. Within lists, tuples, sets, and dictionaries, whitespace can appear before and after commas with no ill effects. However, the Python style guide states that commas should be preceded by zero spaces and followed by one. Although this is purely an aesthetic issue (the code works either way, in both Python 2 and Python 3), the &lt;code&gt;2to3&lt;/code&gt; script can optionally fix this for you.

&lt;br /&gt;
&lt;blockquote class=&quot;note&quot;&gt;
&lt;span class=&quot;u&quot;&gt;☞&lt;/span&gt;The &lt;code&gt;2to3&lt;/code&gt; script will not fix whitespace around commas by default. To enable this fix, specify &lt;kbd&gt;-f wscomma&lt;/kbd&gt; on the command line when you call &lt;code&gt;2to3&lt;/code&gt;.
&lt;/blockquote&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Before
&lt;/th&gt;&lt;th&gt;After

&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a ,b&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;a, b&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;{a :b}&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;{a: b}&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 id=&quot;idioms&quot;&gt;
Common idioms (explicit)&lt;/h3&gt;
There were a number of common idioms built up in the Python community. Some, like the &lt;code&gt;while 1:&lt;/code&gt; loop, date back to Python 1. (Python didn’t have a true boolean type until version 2.3, so developers used &lt;code&gt;1&lt;/code&gt; and 0 instead.)  Modern Python programmers should train their brains to use modern versions of these idioms instead.

&lt;br /&gt;
&lt;blockquote class=&quot;note&quot;&gt;
&lt;span class=&quot;u&quot;&gt;☞&lt;/span&gt;The &lt;code&gt;2to3&lt;/code&gt; script will not fix common idioms by default. To enable this fix, specify &lt;kbd&gt;-f idioms&lt;/kbd&gt; on the command line when you call &lt;code&gt;2to3&lt;/code&gt;.
&lt;/blockquote&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Notes
&lt;/th&gt;&lt;th&gt;Before
&lt;/th&gt;&lt;th&gt;After

&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;while 1:
    do_stuff()&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;while True:
    do_stuff()&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type(x) == T&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;isinstance(x, T)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;type(x) is T&lt;/code&gt;
&lt;/td&gt;&lt;td&gt;&lt;code class=&quot;pp&quot;&gt;isinstance(x, T)&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;a_list = list(a_sequence)
a_list.sort()
do_stuff(a_list)&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;td&gt;&lt;pre class=&quot;pp&quot;&gt;&lt;code&gt;a_list = sorted(a_sequence)
do_stuff(a_list)&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;v&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;c&quot;&gt;
© 2001–11 &lt;a href=&quot;https://www.blogger.com/about.html&quot;&gt;Mark Pilgrim&lt;/a&gt;
&lt;script src=&quot;j/jquery.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;j/prettify.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;j/dip3.js&quot;&gt;&lt;/script&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/546569934104833329/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/porting-code-to-python-3-with-2to3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/546569934104833329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/546569934104833329'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/porting-code-to-python-3-with-2to3.html' title='Porting Code to Python 3 with 2to3'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-5561074214853401159</id><published>2015-01-16T07:27:00.000-08:00</published><updated>2015-11-24T17:56:48.136-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="tutorial"/><title type='text'>Recursive File and Directory Manipulation in Python (Part 3)</title><content type='html'>&lt;br /&gt;
&lt;br /&gt;
&lt;article class=&quot;post-2326 post type-post status-publish format-standard hentry category-uncategorized&quot; id=&quot;post-2326&quot; itemprop=&quot;articleBody&quot;&gt;
Repost from &lt;a href=&quot;http://www.pythoncentral.io/recursive-file-and-directory-manipulation-in-python-part-3/&quot; target=&quot;_blank&quot;&gt;python central&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
In &lt;a href=&quot;http://www.pythoncentral.io/recursive-file-and-directory-manipulation-in-python-part-2/&quot; title=&quot;Recursive File and Directory Manipulation in Python (Part 2)&quot;&gt;Part 2&lt;/a&gt;
 of this series we expanded our file-searching script to be able to 
search for multiple file extensions under a tree, and to write the 
results (all paths to files of matching extensions found) to a log file.
 Now that we&#39;ve come to the final part of the series, we&#39;ll add more 
functionality (in the form of functions) to our script to be able to 
move, copy, and even delete the results of the search.&lt;br /&gt;

Before looking at the move/copy/delete functions, we&#39;ll first take 
the subroutine of logging the results to file and encapsulate that in a 
function also. The following is what that part of our script looked like
 before:&lt;/article&gt;&lt;article class=&quot;post-2326 post type-post status-publish format-standard hentry category-uncategorized&quot; id=&quot;post-2326&quot; itemprop=&quot;articleBody&quot;&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dcddb889159298&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcddb889159298-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The header in our logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-2&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Search log from filefind for files in {}\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;format&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-4&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-5&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The body of our log file&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-6&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-7&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-8&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Loop through results&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-9&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;searchResult &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Concatenate the result from the found dict&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-11&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;&amp;lt;&amp;lt; Results with the extension &#39;%s&#39; &amp;gt;&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;searchResult&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-12&quot;&gt;
&lt;span class=&quot;crayon-e&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n\n%s\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;searchResult&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-13&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-14&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Write results to the logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-15&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;open&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-16&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcddb889159298-17&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
In order to put it into a function definition, we simply put the 
definition statement above, adding the appropriate arguments, and indent
 the rest accordingly (note how &lt;code&gt;found&lt;/code&gt; changes to &lt;code&gt;results&lt;/code&gt; and &lt;code&gt;logname&lt;/code&gt; to &lt;code&gt;logpath&lt;/code&gt;):&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dcde6076814952&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcde6076814952-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Logging results for findfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-2&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;logres&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# The header in our logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Search log from filefind for files in {}\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;format&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-5&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-6&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-7&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# The body of our log file&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-8&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-9&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Loop through results&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-11&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;searchResult &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-12&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Concatenate the result from the results dict&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-13&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;&amp;lt;&amp;lt; Results with the extension &#39;%s&#39; &amp;gt;&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;searchResult&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-14&quot;&gt;
&lt;span class=&quot;crayon-e&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n\n%s\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;searchResult&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-15&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-16&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# write results to the logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-17&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;open&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-18&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcde6076814952-19&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
For error-reporting purposes, we&#39;ll also define a small function to 
write an error log, and we&#39;ll see why shortly. Here is the function for 
that, it takes in 3 arguments and writes a list of strings to an error 
log:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dcdeb859546765&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdeb859546765-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdeb859546765-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdeb859546765-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdeb859546765-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdeb859546765-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdeb859546765-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdeb859546765-1&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;logerr&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlist&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;act&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdeb859546765-2&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;List of files that produced errors when attempting to %s:\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;act&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdeb859546765-3&quot;&gt;
&lt;span class=&quot;crayon-e&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlist&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdeb859546765-4&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdeb859546765-5&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;open&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdeb859546765-6&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
With both of our logging functions defined, we&#39;ll now write our 
functions to perform batch operations on our results list from our file 
search. We will first look at how to perform a batch move on the files 
found from their original locations to a target directory. The function 
we will use to actually move the files is the &lt;code&gt;move&lt;/code&gt; function from the &lt;code&gt;shutil&lt;/code&gt; module (imagine that :P), so we&#39;ll want to add this statement to the beginning of our script:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dcdef430593300&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdef430593300-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdef430593300-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdef430593300-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# We&#39;ll use copy2 later&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdef430593300-2&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;shutil&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-r&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;move&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;copy2&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
For our function definition, instead of acting directly on the &lt;code&gt;found&lt;/code&gt;
 variable in the script, we&#39;ll have our method take in a dictionary of 
results and act on it. It also needs the path to the directory to move 
them to and an error log path, if we want it. It will also need a 
variable to store the errors (a list of path strings to files):&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dcdf2328429606&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdf2328429606-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdf2328429606-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdf2328429606-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdf2328429606-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdf2328429606-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Moving results&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdf2328429606-2&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;batchmove&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-t&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdf2328429606-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# List of results that produce errors&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdf2328429606-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Before writing the rest of the function definition, a few important notes on the &lt;code&gt;move&lt;/code&gt;
 function—firstly, this function will move the source argument to the 
destination of the same type. This means that if the source path is a 
directory, the destination will also be a directory, and likewise for 
files. Secondly, if the destination exists and is a file, then the 
source &lt;i&gt;must&lt;/i&gt; be a file or the function will fail. In other 
words, if the destination is a directory, the source (either file or 
directory) will be moved into the destination directory, but if the 
destination is a file, the source may only be a file (we can&#39;t move a 
directory into a file). With that said, all we need do is make sure the &lt;code&gt;dest&lt;/code&gt; argument to &lt;code&gt;batchmove&lt;/code&gt; is an existing directory, so we&#39;ll use a try statement after testing:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dcdf6442410964&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdf6442410964-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-1&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Make sure dest is a directory!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-2&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;isfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;The move destination &#39;%s&#39; already exists as a file!&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-5&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;elif&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;isdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-6&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-7&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;mkdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-8&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-9&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;Unable to create &#39;%s&#39; folder!&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-11&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdf6442410964-12&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;&#39;%s&#39; folder created&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
This way, if the move fails, it will alert the user and wait before 
exiting. With our destination directory checked, we can add the core of 
the function: looping through &lt;code&gt;results&lt;/code&gt; and moving each file. Here is the loop:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dcdfa391947446&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdfa391947446-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-1&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Loop through results, moving every file to dest directory&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-2&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;paths &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;path &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-5&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-6&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Move file to dest&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-7&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;move&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-8&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-9&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdfa391947446-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;File move complete&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
The keys in &lt;code&gt;results&lt;/code&gt; are simply the file extensions searched for, so only the values are needed, and for each &lt;code&gt;path&lt;/code&gt; in the current &lt;code&gt;paths&lt;/code&gt; list in the values, we try to move it to our destination. If the move fails, the &lt;code&gt;path&lt;/code&gt; is added to the error list. When the loop completes, a message is printed to the standard output.&lt;br /&gt;

After the loop completes, we&#39;ll want to log any errors encountered with our &lt;code&gt;logerr&lt;/code&gt; method like so:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dcdfe115218854&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdfe115218854-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdfe115218854-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dcdfe115218854-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dcdfe115218854-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdfe115218854-1&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Log errors, if any&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdfe115218854-2&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;errlog &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dcdfe115218854-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;logerr&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;move&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dcdfe115218854-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;Check &#39;%s&#39; for errors.&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Finally, we&#39;ll have the script print a final message and exit:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dce01392504875&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce01392504875-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce01392504875-1&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Putting it all together, here is what our &lt;code&gt;batchmove&lt;/code&gt; function looks like:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dce04434880745&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-20&quot; style=&quot;height: 15px;&quot;&gt;
20&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-21&quot; style=&quot;height: 15px;&quot;&gt;
21&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-22&quot; style=&quot;height: 15px;&quot;&gt;
22&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-23&quot; style=&quot;height: 15px;&quot;&gt;
23&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-24&quot; style=&quot;height: 15px;&quot;&gt;
24&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-25&quot; style=&quot;height: 15px;&quot;&gt;
25&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-26&quot; style=&quot;height: 15px;&quot;&gt;
26&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-27&quot; style=&quot;height: 15px;&quot;&gt;
27&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-28&quot; style=&quot;height: 15px;&quot;&gt;
28&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-29&quot; style=&quot;height: 15px;&quot;&gt;
29&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-30&quot; style=&quot;height: 15px;&quot;&gt;
30&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-31&quot; style=&quot;height: 15px;&quot;&gt;
31&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-32&quot; style=&quot;height: 15px;&quot;&gt;
32&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-33&quot; style=&quot;height: 15px;&quot;&gt;
33&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-34&quot; style=&quot;height: 15px;&quot;&gt;
34&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce04434880745-35&quot; style=&quot;height: 15px;&quot;&gt;
35&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Moving results&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-2&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;batchmove&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-t&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# List of results that produce errors&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-5&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-6&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-7&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Make sure dest is a directory!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-8&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;isfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-9&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;The move destination &#39;%s&#39; already exists as a file!&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-11&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;elif&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;isdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-12&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-13&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;mkdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-14&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-15&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;Unable to create &#39;%s&#39; folder!&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-16&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-17&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-18&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;&#39;%s&#39; folder created&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-19&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-20&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Loop through results, moving every file to dest directory&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-21&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;paths &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-22&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;path &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-23&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-24&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-25&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# move file to dest&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-26&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;move&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-27&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-28&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-29&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;File move complete&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-30&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-31&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# log errors, if any&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-32&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;errlog &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-33&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;logerr&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;move&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce04434880745-34&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;Check &#39;%s&#39; for errors.&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce04434880745-35&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Now that we have the &lt;code&gt;batchmove&lt;/code&gt; function, in order to define the &lt;code&gt;batchcopy&lt;/code&gt; function, we need only change the function call of the innermost loop to &lt;code&gt;copy2&lt;/code&gt; (and messages accordingly), so the full definition would look like this:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dce09863381586&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-20&quot; style=&quot;height: 15px;&quot;&gt;
20&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-21&quot; style=&quot;height: 15px;&quot;&gt;
21&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-22&quot; style=&quot;height: 15px;&quot;&gt;
22&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-23&quot; style=&quot;height: 15px;&quot;&gt;
23&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-24&quot; style=&quot;height: 15px;&quot;&gt;
24&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-25&quot; style=&quot;height: 15px;&quot;&gt;
25&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-26&quot; style=&quot;height: 15px;&quot;&gt;
26&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-27&quot; style=&quot;height: 15px;&quot;&gt;
27&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-28&quot; style=&quot;height: 15px;&quot;&gt;
28&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-29&quot; style=&quot;height: 15px;&quot;&gt;
29&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-30&quot; style=&quot;height: 15px;&quot;&gt;
30&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-31&quot; style=&quot;height: 15px;&quot;&gt;
31&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-32&quot; style=&quot;height: 15px;&quot;&gt;
32&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce09863381586-33&quot; style=&quot;height: 15px;&quot;&gt;
33&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Copying results&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-2&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;batchcopy&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-t&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# List of results that produce errors&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-5&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-6&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Make sure dest is a directory!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-7&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;isfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-8&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;The copy destination &#39;%s&#39; already exists as a file!&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-9&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;elif&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;isdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-11&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-12&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;mkdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-13&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-14&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;Unable to create &#39;%s&#39; folder!&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-15&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-16&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-17&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;&#39;%s&#39; folder created&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-18&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-19&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Loop thru results, copying every file to dest directory&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-20&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;paths &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-21&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;path &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-22&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-23&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-24&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# copy file to dest&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-25&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;copy2&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-26&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-27&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-28&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;File copying complete&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-29&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-30&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Log errors, if any&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-31&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;errlog &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce09863381586-32&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;logerr&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;copy&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce09863381586-33&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
These two we&#39;ve defined should be useful enough not to need a 
deletion function, but if we wanted one, we would only have to remove 
the &lt;code&gt;dest&lt;/code&gt; check from &lt;code&gt;batchmove&lt;/code&gt; and change the inner loop function call to &lt;code&gt;os.remove&lt;/code&gt; like so:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b92ce3dce0d864003890&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b92ce3dce0d864003890-20&quot; style=&quot;height: 15px;&quot;&gt;
20&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Deleting results -- USE WITH CAUTION!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-2&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;batchdel&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-t&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# List of results that produce errors&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-5&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-6&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Loop thru results, DELETING every file!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-7&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;paths &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-8&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;path &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-9&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-11&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Delete file&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-12&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-13&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-14&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-15&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;File deletion complete&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-16&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-17&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Log errors, if any&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-18&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;errlog &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-19&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;logerr&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errlog&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;delete&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b92ce3dce0d864003890-20&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;input&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Press enter to exit...&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
This is just to show how we&#39;d implement the deletion subroutine, but 
actually it&#39;s not recommended, because whatever files Python deletes are
 deleted permanently (not sent to the Recycle Bin!). It would be safer 
simply to move the files to a folder with &lt;code&gt;batchmove&lt;/code&gt; and 
delete them from there, but of course the choice is up to you :). Now 
that we&#39;ve defined these functions, all we&#39;d need to do to utilize them 
is call them after the search loop with &lt;code&gt;found&lt;/code&gt; as the &lt;code&gt;results&lt;/code&gt;
 argument, and whatever paths to log files we want accordingly, so 
finding and moving our files around will be a breeze even if we don&#39;t 
know where they are!&lt;br /&gt;

&lt;/article&gt;</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/5561074214853401159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/recursive-file-and-directory_16.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/5561074214853401159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/5561074214853401159'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/recursive-file-and-directory_16.html' title='Recursive File and Directory Manipulation in Python (Part 3)'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-7049275817376684107</id><published>2015-01-16T07:25:00.000-08:00</published><updated>2015-11-24T17:57:32.624-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="tutorial"/><title type='text'>Recursive File and Directory Manipulation in Python (Part 2)</title><content type='html'>&lt;br /&gt;
&lt;br /&gt;
&lt;article class=&quot;post-1395 post type-post status-publish format-standard hentry category-uncategorized&quot; id=&quot;post-1395&quot; itemprop=&quot;articleBody&quot;&gt;
Repost from &lt;a href=&quot;http://www.pythoncentral.io/recursive-file-and-directory-manipulation-in-python-part-2/&quot; target=&quot;_blank&quot;&gt;python central&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
In &lt;a href=&quot;http://www.pythoncentral.io/recursive-file-and-directory-manipulation-in-python-part-1/&quot; title=&quot;Recursive File and Directory Manipulation in Python (Part 1)&quot;&gt;Part 1&lt;/a&gt; we looked at how to use the &lt;a href=&quot;http://www.pythoncentral.io/recursive-file-and-directory-manipulation-in-python-part-1/&quot; title=&quot;Recursive File and Directory Manipulation in Python (Part 1)&quot;&gt;os.path.walk and os.walk methods to find and list files of a certain extension under a directory tree&lt;/a&gt;.
 The former function is only present in the Python 2.x, and the latter 
is available in both Python 2.x and Python 3.x. As we saw in the 
previous article, the &lt;code&gt;os.path.walk&lt;/code&gt; method can be awkward to use, so from now on we&#39;ll stick to the &lt;code&gt;os.walk&lt;/code&gt; method, this way the script will be simpler and compatible with both branches.&lt;br /&gt;

In &lt;a href=&quot;http://www.pythoncentral.io/recursive-file-and-directory-manipulation-in-python-part-1/&quot; title=&quot;Recursive File and Directory Manipulation in Python (Part 1)&quot;&gt;Part 1&lt;/a&gt; our script traversed all the folders under the &lt;code&gt;topdir&lt;/code&gt;
 variable, but only found files of one extension. Let&#39;s now expand that 
to find files of multiple extensions in select folders under the &lt;code&gt;topdir&lt;/code&gt; path. We&#39;ll first search for files of three different file extensions: .txt, .pdf, and .doc. Our &lt;code&gt;extens&lt;/code&gt; variable will be a list of strings instead of one:&lt;/article&gt;&lt;article class=&quot;post-1395 post type-post status-publish format-standard hentry category-uncategorized&quot; id=&quot;post-1395&quot; itemprop=&quot;articleBody&quot;&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c3f782316438&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c3f782316438-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c3f782316438-1&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;extens&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;txt&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;pdf&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;doc&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
The &lt;code&gt;.&lt;/code&gt; character is not included in these strings as it was in the &lt;code&gt;ext&lt;/code&gt;
 variable as before, and we&#39;ll see why shortly. In order to save the 
results (the file names) we&#39;ll use a dictionary with the extensions as 
keys:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c4f984342969&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c4f984342969-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c4f984342969-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c4f984342969-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# List comprehension form of instantiation&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c4f984342969-2&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;extens&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
The other variables will remain the same for now; however, the script
 file itself will be placed in (and will execute from) my system&#39;s 
“Documents” folder, so the &lt;code&gt;topdir&lt;/code&gt; variable will become that path.&lt;br /&gt;

Previously we tested for the extension with the &lt;code&gt;str.endswith&lt;/code&gt; method. If we were to use it again we&#39;d have to loop through the extension list and test with &lt;code&gt;endswith&lt;/code&gt;
 for every file name, but instead we&#39;ll use a slightly different 
approach. For each file stepped on during the walk we&#39;ll extract the 
extension and then test for membership in &lt;i&gt;extens&lt;/i&gt;. Here&#39;s how we&#39;ll extract it:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c57035404002&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c57035404002-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c57035404002-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c57035404002-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c57035404002-1&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;name &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c57035404002-2&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Split the name by &#39;.&#39; &amp;amp; get the last element&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c57035404002-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;rsplit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;“&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;”&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
As with the previous part, we put this line inside the for loop that interates over the &lt;i&gt;files&lt;/i&gt; list returned by &lt;code&gt;os.walk&lt;/code&gt;.
 With this line we combined three operations: changing the case of the 
file name, splitting it, and extracting an element. Calling &lt;code&gt;str.lower&lt;/code&gt; on the filename changes it to lowercase. The same as all strings in &lt;code&gt;extens&lt;/code&gt;. Calling &lt;code&gt;str.rsplit&lt;/code&gt; on &lt;i&gt;name&lt;/i&gt; then splits the string into a list (from the right) with the first argument &lt;code&gt;.&lt;/code&gt; delimiting it, and only making as many splits as the second argument (1). The third part (&lt;code&gt;[-1]&lt;/code&gt;) retrieves the last element of the list—we use this instead of an index of 1 because if no splits are made (if there is no &lt;code&gt;.&lt;/code&gt; in &lt;code&gt;name&lt;/code&gt;), no &lt;code&gt;IndexError&lt;/code&gt; will be raised.&lt;br /&gt;

Now that we&#39;ve extracted the extension of &lt;code&gt;name&lt;/code&gt; (if any), we can test to see if it&#39;s in our list of extensions:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c5f613391455&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c5f613391455-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c5f613391455-1&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;ext &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;extens&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
This is why &lt;code&gt;.&lt;/code&gt; doesn&#39;t precede any of the extension names in &lt;code&gt;extens&lt;/code&gt;, because &lt;code&gt;ext&lt;/code&gt; won&#39;t ever have one. If the condition is true, we&#39;ll add the name found to our &lt;code&gt;found&lt;/code&gt; dictionary:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c65168029663&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c65168029663-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c65168029663-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c65168029663-1&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;ext &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;extens&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c65168029663-2&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
The above line will append the result path (&lt;code&gt;dirpath&lt;/code&gt; joined to &lt;code&gt;name&lt;/code&gt; returned from &lt;code&gt;os.walk&lt;/code&gt;) to the list at the &lt;code&gt;ext&lt;/code&gt; key in &lt;code&gt;found&lt;/code&gt;.
 Now that we have changed the search extensions and list of results we 
also have to adjust how to save the results to our log file.&lt;br /&gt;

In the previous version (using &lt;code&gt;os.walk&lt;/code&gt;) we simply opened a file at &lt;code&gt;logname&lt;/code&gt;
 and wrote the results to the file. In this version we must loop through
 multiple categories in the results, one for each extension. We&#39;ll 
concatenate each result list in &lt;code&gt;found&lt;/code&gt; to our results string, which we&#39;ll now identify as &lt;code&gt;logbody&lt;/code&gt;. We&#39;ll also add a small header to the logfile, &lt;i&gt;loghead&lt;/i&gt;:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c6b106847298&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c6b106847298-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The header in our logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-2&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Search log from filefind for files in {}\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;format&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-4&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The body of our log file&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-5&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-6&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-7&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Loop through results&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-8&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;search &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-9&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Concatenate the result from the found dict&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;&amp;lt;&amp;lt; Results with the extension &#39;%s&#39; &amp;gt;&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;search&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-11&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-12&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Use str.join to turn the list at search into a str&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c6b106847298-13&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n\n%s\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
The format of the results can be whatever or however you like, but it
 is important that we loop through all of the results to get the full 
log. After the &lt;code&gt;logbody&lt;/code&gt; is complete, we can write our log file:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c72469114417&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c72469114417-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c72469114417-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c72469114417-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c72469114417-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Write results to the logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c72469114417-2&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;open&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c72469114417-3&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;%s\n%s&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;i&gt;Note:&lt;/i&gt; if any names/paths in the solution contain non-ASCII characters, we would have to change the &lt;code&gt;open&lt;/code&gt; mode to &lt;code&gt;wb&lt;/code&gt; and decode &lt;code&gt;loghead&lt;/code&gt; and &lt;code&gt;logbody&lt;/code&gt; (or encode if in Python 3.x) in order to save the &lt;code&gt;logfile&lt;/code&gt; successfully.&lt;br /&gt;

Now we are finally ready to test our script. Running it on my system yields this log file (shortened):&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c78131084612&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c78131084612-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-1&quot;&gt;
&lt;span class=&quot;crayon-e&quot;&gt;Search &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;log &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;from &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;filefind &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;files &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;Python27&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;Lib&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;site&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;packages&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-2&quot;&gt;
&lt;span class=&quot;crayon-o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;Results &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;with &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;the &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;extension&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;pdf&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-3&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;GPL_Full&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.pdf&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-4&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;beautifulsoup4&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;4.1.3&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;doc&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;rfc2425&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;v2&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;1.pdf&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-5&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;beautifulsoup4&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;4.1.3&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;doc&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;rfc2426&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;v3&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;0.pdf&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-6&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-7&quot;&gt;
&lt;span class=&quot;crayon-o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;Results &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;with &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;the &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;extension&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;txt&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-8&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;README&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-9&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;soup&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-10&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;beautifulsoup4&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;4.1.3&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;AUTHORS&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-11&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;beautifulsoup4&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;4.1.3&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;COPYING&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-12&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-13&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;docs&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;CHANGES&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-14&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;docs&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;MigrationGuide&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-15&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;docs&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;README&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.win32&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-16&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-17&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;XRCed&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;TODO&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c78131084612-18&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c78131084612-19&quot;&gt;
&lt;span class=&quot;crayon-o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;Results &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;with &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;the &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;extension&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;doc&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
This log tells us that in the &lt;code&gt;C:\Python27\Lib\site-packages&lt;/code&gt;
 directory there are a few PDF files, many text files, and no &quot;.doc&quot; or 
Word files. It seems to work fine, and the extension search list can be 
changed easily, but what if we don&#39;t want to search in the &quot;docs&quot; 
directory under the &lt;code&gt;wx-2.8-msw-unicode&lt;/code&gt; tree? After all, we know there will probably be lots of text files in there. We can ignore this directory by modifying the &lt;code&gt;dirnames&lt;/code&gt;
 list in-place in the main walk loop. Because we might want to ignore 
more than one directory, we&#39;ll keep a list of them (this will come 
before the loop of course):&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c7f754183151&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c7f754183151-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c7f754183151-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c7f754183151-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Directories to ignore&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c7f754183151-2&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;ignore&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;docs&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;doc&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Now that we have the list, we&#39;ll add this small loop inside the main walk loop (and before the loop over the file names):&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c86729947585&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c86729947585-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c86729947585-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c86729947585-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c86729947585-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c86729947585-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c86729947585-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c86729947585-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Remove directories in ignore&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c86729947585-2&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c86729947585-3&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Directory names must match exactly!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c86729947585-4&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;idir &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ignore&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c86729947585-5&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;idir &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirnames&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c86729947585-6&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirnames&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;idir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
This will edit &lt;code&gt;dirnames&lt;/code&gt; in-place, so that the next 
iteration of the walk loop will no longer include the folders named in 
ignore. The full script with the new walk loop now looks like this:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c8c928992136&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-20&quot; style=&quot;height: 15px;&quot;&gt;
20&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-21&quot; style=&quot;height: 15px;&quot;&gt;
21&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-22&quot; style=&quot;height: 15px;&quot;&gt;
22&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-23&quot; style=&quot;height: 15px;&quot;&gt;
23&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-24&quot; style=&quot;height: 15px;&quot;&gt;
24&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-25&quot; style=&quot;height: 15px;&quot;&gt;
25&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-26&quot; style=&quot;height: 15px;&quot;&gt;
26&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-27&quot; style=&quot;height: 15px;&quot;&gt;
27&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-28&quot; style=&quot;height: 15px;&quot;&gt;
28&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-29&quot; style=&quot;height: 15px;&quot;&gt;
29&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-30&quot; style=&quot;height: 15px;&quot;&gt;
30&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-31&quot; style=&quot;height: 15px;&quot;&gt;
31&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-32&quot; style=&quot;height: 15px;&quot;&gt;
32&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-33&quot; style=&quot;height: 15px;&quot;&gt;
33&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-34&quot; style=&quot;height: 15px;&quot;&gt;
34&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-35&quot; style=&quot;height: 15px;&quot;&gt;
35&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-36&quot; style=&quot;height: 15px;&quot;&gt;
36&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-37&quot; style=&quot;height: 15px;&quot;&gt;
37&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-38&quot; style=&quot;height: 15px;&quot;&gt;
38&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-39&quot; style=&quot;height: 15px;&quot;&gt;
39&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-40&quot; style=&quot;height: 15px;&quot;&gt;
40&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-41&quot; style=&quot;height: 15px;&quot;&gt;
41&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-42&quot; style=&quot;height: 15px;&quot;&gt;
42&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-43&quot; style=&quot;height: 15px;&quot;&gt;
43&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-44&quot; style=&quot;height: 15px;&quot;&gt;
44&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-45&quot; style=&quot;height: 15px;&quot;&gt;
45&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-46&quot; style=&quot;height: 15px;&quot;&gt;
46&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-47&quot; style=&quot;height: 15px;&quot;&gt;
47&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-48&quot; style=&quot;height: 15px;&quot;&gt;
48&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c8c928992136-49&quot; style=&quot;height: 15px;&quot;&gt;
49&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-1&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-2&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-3&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The top argument for name in files&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-4&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-5&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-6&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;extens&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;txt&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;pdf&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;doc&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# the extensions to search for&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-7&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-8&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;extens&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# lists of found files&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-9&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-10&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Directories to ignore&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-11&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;ignore&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;docs&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;doc&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-12&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-13&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;logname&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;findfiletypes.log&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-14&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-15&quot;&gt;
&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Beginning search for files in %s&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-16&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-17&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Walk the tree&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-18&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirnames&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;files &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;walk&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-19&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Remove directories in ignore&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-20&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# directory names must match exactly!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-21&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;idir &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ignore&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-22&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;idir &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirnames&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-23&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirnames&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;idir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-24&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-25&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Loop through the file names for the current step&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-26&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;name &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-27&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Split the name by &#39;.&#39; &amp;amp; get the last element&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-28&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;rsplit&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-29&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-30&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Save the full name if ext matches&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-31&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;ext &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;extens&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-32&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-33&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-34&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The header in our logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-35&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;Search log from filefind for files in {}\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;format&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-36&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;realpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-37&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-38&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The body of our log file&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-39&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-40&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-41&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# loop thru results&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-42&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;search &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-43&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Concatenate the result from the found dict&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-44&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&quot;&amp;lt;&amp;lt; Results with the extension &#39;%s&#39; &amp;gt;&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;search&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-45&quot;&gt;
&lt;span class=&quot;crayon-e&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n\n%s\n\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-46&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-47&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Write results to the logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-48&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;open&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c8c928992136-49&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;%s\n%s&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;loghead&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logbody&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
With our new ignored files element, the log file turns out looking like this (shortened):&lt;br /&gt;

Search log from &lt;code&gt;filefind&lt;/code&gt; for files in &lt;code&gt;C:\Python27\Lib\site-packages&lt;/code&gt;&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e8f812c94999193165&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e8f812c94999193165-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c94999193165-1&quot;&gt;
&lt;span class=&quot;crayon-o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;Results &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;with &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;the &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;extension&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;pdf&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c94999193165-2&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;GPL_Full&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.pdf&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c94999193165-3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c94999193165-4&quot;&gt;
&lt;span class=&quot;crayon-o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;Results &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;with &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;the &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;extension&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;txt&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c94999193165-5&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;README&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c94999193165-6&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;soup&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c94999193165-7&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;beautifulsoup4&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;4.1.3&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;AUTHORS&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c94999193165-8&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;beautifulsoup4&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;4.1.3&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;COPYING&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c94999193165-9&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c94999193165-10&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;beautifulsoup4&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;4.1.3&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;scripts&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;demonstration_markup&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c94999193165-11&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;lib&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;editor&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;README&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c94999193165-12&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c94999193165-13&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;XRCed&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;TODO&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e8f812c94999193165-14&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e8f812c94999193165-15&quot;&gt;
&lt;span class=&quot;crayon-o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;Results &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;with &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;the &lt;/span&gt;&lt;span class=&quot;crayon-i&quot;&gt;extension&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;doc&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Our ignore list worked just as we wanted it to, cutting out the full tree under the &quot;docs&quot; directory in &lt;code&gt;wx-...-unicode&lt;/code&gt;.
 We can also see that the other ignore directory (&quot;doc&quot;) cut out the 
other two PDF files from our PDF results, and for both directories we 
didn&#39;t need to name the full path (because the name won&#39;t be the full 
path in &lt;code&gt;dirnames&lt;/code&gt; anyway). This can be convenient but always remember that this method will prune out &lt;i&gt;any&lt;/i&gt; part of the tree under any name that matches one in the &lt;code&gt;ignore&lt;/code&gt; list (to avoid this try using the &lt;code&gt;dirpath&lt;/code&gt; and &lt;code&gt;dirnames&lt;/code&gt; together to specify full paths to ignore, if you don&#39;t mind going through the trouble of naming the full path!).&lt;br /&gt;

Now that we&#39;ve completed this version of our file/directory 
manipulation script, we can search for multiple file extensions under 
any tree fast and have a record of all those found with just a 
double-click. This is great if we simply want to &lt;i&gt;know&lt;/i&gt; where all
 the files exist, but since they likely will not all be in the same 
folder, if we wanted to move/copy them all to the same folder or do 
something else with all of them simultaneously, looking through each 
line of the log file would &lt;b&gt;not&lt;/b&gt; be preferable. This is 
why in the next part we&#39;ll look at how to upgrade our script to move, 
copy/backup, or alternatively erase all the files we are looking for.&lt;br /&gt;

&lt;/article&gt;</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/7049275817376684107/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/recursive-file-and-directory.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/7049275817376684107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/7049275817376684107'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/recursive-file-and-directory.html' title='Recursive File and Directory Manipulation in Python (Part 2)'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-4462035800884920764</id><published>2015-01-16T07:19:00.000-08:00</published><updated>2015-11-24T17:57:54.536-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="tutorial"/><title type='text'>Recursive File and Directory Manipulation in Python (Part 1)</title><content type='html'>&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;article class=&quot;post-1305 post type-post status-publish format-standard hentry category-uncategorized&quot; id=&quot;post-1305&quot; itemprop=&quot;articleBody&quot;&gt;
Repost from &lt;a href=&quot;http://www.pythoncentral.io/recursive-file-and-directory-manipulation-in-python-part-1/&quot; target=&quot;_blank&quot;&gt;python central&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
If you are looking to utilize Python to manipulate your directory 
tree or files on your system, there are many tools to help, including 
Python&#39;s standard os module. The following is a simple/basic recipe to 
assist with finding certain files on your system by file extension.&lt;br /&gt;

If you have had the experience of &quot;losing&quot; a file in your system 
where you don&#39;t remember its location and are not even sure of its name,
 though you remember its type, this is where you might find this recipe 
useful.&lt;br /&gt;

In a way this recipe is a combination of &lt;a href=&quot;http://www.pythoncentral.io/how-to-traverse-a-directory-tree-in-python-guide-to-os-walk/&quot; title=&quot;How to Traverse a Directory Tree&quot;&gt;How to Traverse a Directory Tree&lt;/a&gt; and &lt;a href=&quot;http://www.pythoncentral.io/recursive-python-function-example-make-list-movies/&quot; title=&quot; Recursive Directory Traversal in Python: Make a list of your movies!&quot;&gt;Recursive Directory Traversal in Python: Make a list of your movies!&lt;/a&gt;, but we&#39;ll tweak it a bit and build upon it in part two.&lt;br /&gt;

To script this task, we can use the &lt;code&gt;walk&lt;/code&gt; function in the &lt;code&gt;os.path&lt;/code&gt; module or the &lt;code&gt;walk&lt;/code&gt; function in the &lt;code&gt;os&lt;/code&gt; module (using Python version 2.x or Python 3.x, respectively).&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&amp;nbsp;&lt;h1&gt;
Recursion with os.path.walk in Python 2.x&lt;/h1&gt;
The &lt;code&gt;os.path.walk&lt;/code&gt; function takes 3 arguments:&lt;br /&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;arg&lt;/code&gt; - an arbitrary (but mandatory) argument.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;visit&lt;/code&gt; - a function to execute upon each iteration.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;top&lt;/code&gt; - the top of the directory tree to walk.&lt;/li&gt;
&lt;/ol&gt;
It then &lt;i&gt;walks&lt;/i&gt; through the directory tree under the top, 
performing the function at every step. Let&#39;s examine the function (which
 we&#39;ll define as &quot;step&quot;) we use to print the path names of the files 
under top that have the file extension we can provide through &lt;code&gt;arg&lt;/code&gt;.&lt;br /&gt;

Here is the definition of step:&lt;br /&gt;

&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e887d2edc872392700&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2edc872392700-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2edc872392700-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2edc872392700-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2edc872392700-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2edc872392700-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2edc872392700-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2edc872392700-1&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2edc872392700-2&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2edc872392700-3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2edc872392700-4&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;name &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2edc872392700-5&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2edc872392700-6&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Now let&#39;s break it down line-by-line, but first it&#39;s very important 
to point out that the arguments given to step are being passed by 
directly the &lt;code&gt;os.path.walk&lt;/code&gt; function, &lt;b&gt;not&lt;/b&gt; by the user. The three arguments that walk passes on each iteration are:&lt;br /&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;ext&lt;/code&gt; - the arbitrary argument given to &lt;code&gt;os.path.walk&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dirname&lt;/code&gt; - the directory name for that iteration.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;names&lt;/code&gt; - the names of all files under &lt;code&gt;dirname&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
The first line of our step function is of course our declaration of 
the function, and inclusion of the default arguments that will be passed
 directly by &lt;code&gt;os.path.walk&lt;/code&gt;.&lt;br /&gt;

The second line ensures our &lt;code&gt;ext&lt;/code&gt; string is lowercase. The
 third line begins our loop of the argument names, which is a list type.
 The fourth line is how we retrieve the names of files with the 
extension we want, using the string method &lt;code&gt;endswith&lt;/code&gt; to test for a suffix.&lt;br /&gt;

The final line prints the path of any file that passes the suffix (extension) test, concatenating the &lt;code&gt;dirname&lt;/code&gt; argument to the name (with the appropriate system-dependent separator).&lt;br /&gt;

Now after combining our step function with the walk function, the script looks something like this:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e887d2ee9621246395&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ee9621246395-20&quot; style=&quot;height: 15px;&quot;&gt;
20&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# We only need to import this module&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-2&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-4&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The top argument for walk. The&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-5&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Python27/Lib/site-packages folder in my case&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-6&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-7&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-8&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-9&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The arg argument for walk, and subsequently ext for step&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-10&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;exten&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.txt&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-11&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-12&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-13&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-14&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-15&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;name &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-16&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-17&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-18&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-19&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Start the walk&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ee9621246395-20&quot;&gt;
&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;walk&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;exten&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
For my system I have &lt;code&gt;wx_py&lt;/code&gt; installed in the site-packages for Python 2.7, the output looks like this:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e887d2eed357404573&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eed357404573-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eed357404573-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eed357404573-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eed357404573-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eed357404573-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eed357404573-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eed357404573-1&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;README&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eed357404573-2&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;docs&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;CHANGES&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eed357404573-3&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;docs&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;MigrationGuide&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eed357404573-4&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;docs&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;README&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.win32&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eed357404573-5&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eed357404573-6&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-cn&quot;&gt;2.8&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;msw&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;unicode&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;wx&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;XRCed&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;TODO&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;blockquote&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h1&gt;
Recursion with os.walk in Python 3.x&lt;/h1&gt;
Now let&#39;s do the same using Python 3.x.&lt;br /&gt;

The &lt;code&gt;os.walk&lt;/code&gt; function in Python 3.x works differently, 
providing a few more options than the other. It takes 4 arguments, and 
only the first is mandatory. The arguments (and their default values) in
 order are:&lt;br /&gt;

&lt;ul&gt;&lt;code&gt;top&lt;/code&gt; - the root of the directory to walk.&lt;br /&gt;&lt;code&gt;topdown(=True)&lt;/code&gt; - &lt;i&gt;boolean&lt;/i&gt; designating top-down or bottom-up walking.&lt;br /&gt;&lt;code&gt;onerror(=None)&lt;/code&gt; - name of a function to call if an error occurs.&lt;br /&gt;&lt;code&gt;followlinks(=False)&lt;/code&gt; - &lt;i&gt;boolean&lt;/i&gt; designating whether or not to follow symbolic links.
&lt;/ul&gt;
The only one we are concerned with for now is the first. Aside from 
the arguments, perhaps the biggest difference in the two versions of the
 walk function is that the Python 2.x version automatically iterates 
over the directory tree, while the Python 3.x version produces a 
generator function. This means that the Python 3.x version will only go 
to the next iteration when we tell it to, and the way we will do that is
 with a loop.&lt;br /&gt;

Instead of defining a separate function to call as with &lt;i&gt;step&lt;/i&gt; we will write the &lt;code&gt;os.walk&lt;/code&gt; generator into the loop that went into the &lt;code&gt;step&lt;/code&gt; function. Like the Python 2.x version, &lt;code&gt;os.walk&lt;/code&gt;
 produces 3 values we can use for every iteration (the directory path, 
the directory names, and the filenames), but this time they are in the 
form of a 3-tuple, so we have to adjust our method accordingly. Other 
than that we won&#39;t change the extension suffix test at all, so the 
script ends up looking something like this:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e887d2ef2862526775&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2ef2862526775-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-1&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-2&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-3&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The top argument for walk&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-4&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-5&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-6&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The extension to search for&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-7&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;exten&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.txt&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-8&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-9&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirnames&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;files &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;walk&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-10&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;name &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-11&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;exten&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2ef2862526775-12&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;print&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Because my system&#39;s Python32/Lib/site-packages folder contains nothing special, the output for this one ends up being just:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e887d2ef8395410474&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2ef8395410474-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2ef8395410474-1&quot;&gt;
&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;README&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;.txt&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
This will work the same way for whatever the &quot;topdir&quot; and &quot;exten&quot; 
strings are set to; however, this script simply prints the filenames to 
the window (in our examples the Python IDLE window), and if there are 
many files to print this leaves our interpreter (or shell) window many 
rows high—kind of a pain to scroll through.&amp;nbsp;If we know that this is the 
case, it would be much easier to write the results to a text file we can
 look at anytime. We can do so easily if we incorporate a &lt;code&gt;with&lt;/code&gt; statement (as in &lt;a href=&quot;http://www.pythoncentral.io/reading-and-writing-to-files-in-python/&quot;&gt;Reading and Writing Files in Python&lt;/a&gt;) like so:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e887d2efc053022279&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2efc053022279-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2efc053022279-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2efc053022279-1&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;open&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2efc053022279-2&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;%s\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
Let&#39;s see first how to incorporate it into the version Python 2.x script:&lt;br /&gt;


&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e887d2eff367130040&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-20&quot; style=&quot;height: 15px;&quot;&gt;
20&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-21&quot; style=&quot;height: 15px;&quot;&gt;
21&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-22&quot; style=&quot;height: 15px;&quot;&gt;
22&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-23&quot; style=&quot;height: 15px;&quot;&gt;
23&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2eff367130040-24&quot; style=&quot;height: 15px;&quot;&gt;
24&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-1&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# We only need to import this module&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-2&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-3&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-4&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The top argument for walk. The&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-5&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Python27/Lib/site-packages folder in my case.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-6&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-7&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-8&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The arg argument for walk, and subsequently ext for step&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-9&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;exten&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.txt&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-10&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-11&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;logname&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;findfiletype.log&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-12&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-13&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-14&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-15&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-16&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;name &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-17&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-18&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Instead of printing, open up the log file for appending&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-19&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;open&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-20&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;%s\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-21&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-22&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Change the arg to a tuple containing the file&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2eff367130040-23&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# extension and the log file name. Start the walk.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2eff367130040-24&quot;&gt;
&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;walk&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;exten&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
As we can see above, not much has changed except for the third variable &lt;code&gt;logname&lt;/code&gt;, and the third argument to &lt;code&gt;os.path.walk&lt;/code&gt;. The with statement has replaced the &lt;code&gt;print&lt;/code&gt; statement. Because of the nature of &lt;code&gt;os.path.walk&lt;/code&gt; function, &lt;code&gt;step&lt;/code&gt;
 is required to open up the log file, write to it, and close it every 
time it finds a file name; this won&#39;t cause any errors but is a bit 
awkward. We must also note that because the log file is opened up in 
append mode, it will &lt;b&gt;not&lt;/b&gt; overwrite a log file that exists already, it will &lt;b&gt;only append&lt;/b&gt; to the file. This means if we run the script 2 or more times in a row without changing the&amp;nbsp;&lt;code&gt;logname&lt;/code&gt;, the results for each run will be added to the same file, which may not be desirable.&lt;br /&gt;

The modified version Python 3.x script is much less awkward:&lt;br /&gt;

&lt;div class=&quot;crayon-syntax crayon-theme-idle crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped&quot; data-settings=&quot; no-popup minimize scroll-mouseover disable-anim wrap&quot; id=&quot;crayon-54b8e887d2f04774756150&quot; style=&quot;font-size: 13px ! important; height: auto; line-height: 15px ! important; margin-bottom: 12px; margin-top: 12px;&quot;&gt;
&lt;div class=&quot;crayon-main&quot; style=&quot;overflow: hidden; position: relative; z-index: 1;&quot;&gt;
&lt;table class=&quot;crayon-table&quot;&gt;
&lt;tbody&gt;
&lt;tr class=&quot;crayon-row&quot;&gt;
&lt;td class=&quot;crayon-nums &quot; data-settings=&quot;show&quot;&gt;&lt;div class=&quot;crayon-nums-content&quot; style=&quot;font-size: 13px !important; line-height: 15px !important;&quot;&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-1&quot; style=&quot;height: 15px;&quot;&gt;
1&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-2&quot; style=&quot;height: 15px;&quot;&gt;
2&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-3&quot; style=&quot;height: 15px;&quot;&gt;
3&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-4&quot; style=&quot;height: 15px;&quot;&gt;
4&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-5&quot; style=&quot;height: 15px;&quot;&gt;
5&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-6&quot; style=&quot;height: 15px;&quot;&gt;
6&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-7&quot; style=&quot;height: 15px;&quot;&gt;
7&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-8&quot; style=&quot;height: 15px;&quot;&gt;
8&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-9&quot; style=&quot;height: 15px;&quot;&gt;
9&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-10&quot; style=&quot;height: 15px;&quot;&gt;
10&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-11&quot; style=&quot;height: 15px;&quot;&gt;
11&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-12&quot; style=&quot;height: 15px;&quot;&gt;
12&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-13&quot; style=&quot;height: 15px;&quot;&gt;
13&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-14&quot; style=&quot;height: 15px;&quot;&gt;
14&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-15&quot; style=&quot;height: 15px;&quot;&gt;
15&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-16&quot; style=&quot;height: 15px;&quot;&gt;
16&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-17&quot; style=&quot;height: 15px;&quot;&gt;
17&lt;/div&gt;
&lt;div class=&quot;crayon-num crayon-striped-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-18&quot; style=&quot;height: 15px;&quot;&gt;
18&lt;/div&gt;
&lt;div class=&quot;crayon-num&quot; data-line=&quot;crayon-54b8e887d2f04774756150-19&quot; style=&quot;height: 15px;&quot;&gt;
19&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td class=&quot;crayon-code&quot;&gt;&lt;div class=&quot;crayon-pre&quot; style=&quot;-moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; font-size: 13px !important; line-height: 15px !important; tab-size: 4;&quot;&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-1&quot;&gt;
&lt;span class=&quot;crayon-r&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-2&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-3&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The top argument for walk&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-4&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-5&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# The extension to search for&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-6&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;exten&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;.txt&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-7&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;logname&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;findfiletype.log&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-8&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# What will be logged&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-9&quot;&gt;
&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;str&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-10&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-11&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirnames&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;files &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;walk&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;topdir&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-12&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;name &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-13&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;exten&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-14&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-c&quot;&gt;# Save to results string instead of printing&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-15&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;%s\n&#39;&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;os.path&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;dirpath&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-16&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-17&quot;&gt;
&lt;span class=&quot;crayon-c&quot;&gt;# Write results to logfile&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line crayon-striped-line&quot; id=&quot;crayon-54b8e887d2f04774756150-18&quot;&gt;
&lt;span class=&quot;crayon-st&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-k &quot;&gt;open&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logname&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-s&quot;&gt;&#39;w&#39;&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-st&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;crayon-h&quot;&gt; &lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-o&quot;&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;crayon-line&quot; id=&quot;crayon-54b8e887d2f04774756150-19&quot;&gt;
&lt;span class=&quot;crayon-h&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;logfile&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;crayon-e&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;crayon-v&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;crayon-sy&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
In this version the name of each found file is appended to the &lt;code&gt;results&lt;/code&gt;
 string, and then when the search is over, the results are written to 
the log file. Unlike the Python 2.x version, the log file is opened in &lt;i&gt;write&lt;/i&gt; mode, meaning any existing log file &lt;b&gt;will&lt;/b&gt;
 be overwritten.&amp;nbsp;In both cases the log file will be written in the same 
directory as the script (because we didn&#39;t specify a full path name).&lt;br /&gt;

With that we have a simple script to find files of a certain 
extension under a file tree and log those results. In the parts that 
follow we&#39;ll build upon this adding functionality to search for multiple
 file types, avoid certain paths, and more.&lt;br /&gt;

&lt;/article&gt;</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/4462035800884920764/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/repost-from-python-central.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/4462035800884920764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/4462035800884920764'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/repost-from-python-central.html' title='Recursive File and Directory Manipulation in Python (Part 1)'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-1797132843450528529</id><published>2015-01-15T19:24:00.000-08:00</published><updated>2015-11-24T17:58:10.032-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="tutorial"/><title type='text'>30 Python Language Features and Tricks You May Not Know About</title><content type='html'>&lt;div class=&quot;section&quot; id=&quot;unpacking&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;I re post this one, from &lt;a href=&quot;http://sahandsaba.com/thirty-python-language-features-and-tricks-you-may-not-know.html&quot; target=&quot;_blank&quot;&gt;here,&lt;/a&gt;&lt;/span&gt; when I surfing other python programmer and developer.&lt;br /&gt;
&lt;br /&gt;
Sometimes we don&#39;t know about secret of python code, it should be find by self exploring or should be discuss with other python programmer. :-) soo we will get new knowledges. Don&#39;t forget to share to other programmer if you have good tips or trick to tweak something. Let&#39;s make good knowledges share media with wathever you want.&lt;br /&gt;
&lt;h3&gt;
1.1&amp;nbsp;&amp;nbsp;&amp;nbsp;Unpacking&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2, 3)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2, 3)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 3, 5)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;unpacking-for-swapping-variables&quot;&gt;
&lt;h3&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;1.2&amp;nbsp;&amp;nbsp;&amp;nbsp;Unpacking for swapping variables&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 1)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;extended-unpacking-python-3-only&quot;&gt;
&lt;h3&gt;
1.3&amp;nbsp;&amp;nbsp;&amp;nbsp;Extended unpacking (Python 3 only)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[2, 3, 4]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;5&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;negative-indexing&quot;&gt;
&lt;h3&gt;
1.4&amp;nbsp;&amp;nbsp;&amp;nbsp;Negative indexing&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;8&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;list-slices-a-start-end&quot;&gt;
&lt;h3&gt;
1.5&amp;nbsp;&amp;nbsp;&amp;nbsp;List slices (&lt;tt class=&quot;docutils literal&quot;&gt;a[start:end]&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[2, 3, 4, 5, 6, 7]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;list-slices-with-negative-indexing&quot;&gt;
&lt;h3&gt;
1.6&amp;nbsp;&amp;nbsp;&amp;nbsp;List slices with negative indexing&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[7, 8]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;list-slices-with-step-a-start-end-step&quot;&gt;
&lt;h3&gt;
1.7&amp;nbsp;&amp;nbsp;&amp;nbsp;List slices with step (&lt;tt class=&quot;docutils literal&quot;&gt;a[start:end:step]&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[0, 2, 4, 6, 8, 10]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[0, 3, 6, 9]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[2, 4, 6]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;list-slices-with-negative-step&quot;&gt;
&lt;h3&gt;
1.8&amp;nbsp;&amp;nbsp;&amp;nbsp;List slices with negative step&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[::&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[::&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[10, 8, 6, 4, 2, 0]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;list-slice-assignment&quot;&gt;
&lt;h3&gt;
1.9&amp;nbsp;&amp;nbsp;&amp;nbsp;List slice assignment&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[1, 2, 0, 0, 4, 5]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[1, 8, 9, 2, 0, 0, 4, 5]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[1, 5]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;naming-slices-slice-start-end-step&quot;&gt;
&lt;h3&gt;
1.10&amp;nbsp;&amp;nbsp;&amp;nbsp;Naming slices (&lt;tt class=&quot;docutils literal&quot;&gt;slice(start, end, step)&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LASTTHREE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;slice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LASTTHREE&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;slice(-3, None, None)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LASTTHREE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[3, 4, 5]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;iterating-over-list-index-and-value-pairs-enumerate&quot;&gt;
&lt;h3&gt;
1.11&amp;nbsp;&amp;nbsp;&amp;nbsp;Iterating over list index and value pairs (&lt;tt class=&quot;docutils literal&quot;&gt;enumerate&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;Hello&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;world&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;!&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;{}: {}&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0: Hello&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1: world&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2: !&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;iterating-over-dictionary-key-and-value-pairs-dict-iteritems&quot;&gt;
&lt;h3&gt;
1.12&amp;nbsp;&amp;nbsp;&amp;nbsp;Iterating over dictionary key and value pairs (&lt;tt class=&quot;docutils literal&quot;&gt;dict.iteritems&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;c&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;d&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iteritems&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;{}: {}&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;a: 1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;c: 3&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;b: 2&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;d: 4&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
Note: use &lt;tt class=&quot;docutils literal&quot;&gt;dict.items&lt;/tt&gt; in Python 3.&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;zipping-and-unzipping-lists-and-iterables&quot;&gt;
&lt;h3&gt;
1.13&amp;nbsp;&amp;nbsp;&amp;nbsp;Zipping and unzipping lists and iterables&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;c&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, &#39;a&#39;), (2, &#39;b&#39;), (3, &#39;c&#39;)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, 2, 3), (&#39;a&#39;, &#39;b&#39;, &#39;c&#39;)]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;grouping-adjacent-list-items-using-zip&quot;&gt;
&lt;h3&gt;
1.14&amp;nbsp;&amp;nbsp;&amp;nbsp;Grouping adjacent list items using zip&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c&quot;&gt;# Using iterators&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group_adjacent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group_adjacent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, 2, 3), (4, 5, 6)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group_adjacent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, 2), (3, 4), (5, 6)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group_adjacent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1,), (2,), (3,), (4,), (5,), (6,)]&lt;/span&gt;


&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c&quot;&gt;# Using slices&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;itertools&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;islice&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group_adjacent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;islice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group_adjacent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, 2, 3), (4, 5, 6)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group_adjacent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, 2), (3, 4), (5, 6)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group_adjacent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1,), (2,), (3,), (4,), (5,), (6,)]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;section&quot; id=&quot;sliding-windows-n-grams-using-zip-and-iterators&quot;&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
1.15&amp;nbsp;&amp;nbsp;&amp;nbsp;Sliding windows (&lt;span class=&quot;math&quot;&gt;&lt;span class=&quot;MathJax_Preview&quot;&gt;&lt;/span&gt;&lt;span class=&quot;MathJax&quot; id=&quot;MathJax-Element-1-Frame&quot; role=&quot;textbox&quot;&gt;&lt;nobr&gt;&lt;span class=&quot;math&quot; id=&quot;MathJax-Span-1&quot; style=&quot;display: inline-block; width: 0.746em;&quot;&gt;&lt;span style=&quot;display: inline-block; font-size: 123%; height: 0px; position: relative; width: 0.598em;&quot;&gt;&lt;span style=&quot;clip: rect(1.951em, 1000em, 2.603em, -0.278em); left: 0em; position: absolute; top: -2.492em;&quot;&gt;&lt;span class=&quot;mrow&quot; id=&quot;MathJax-Span-2&quot;&gt;&lt;span class=&quot;mi&quot; id=&quot;MathJax-Span-3&quot; style=&quot;font-family: &amp;quot;mathjax_math&amp;quot;; font-style: italic;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;display: inline-block; height: 2.492em; width: 0px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;border-left: 0em solid; display: inline-block; height: 0.639em; overflow: hidden; vertical-align: -0.054em; width: 0px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/span&gt;-grams) using zip and iterators&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;itertools&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;islice&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;n_grams&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;islice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_grams&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_grams&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_grams&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, 2, 3, 4), (2, 3, 4, 5), (3, 4, 5, 6)]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;inverting-a-dictionary-using-zip&quot;&gt;
&lt;h3&gt;
1.16&amp;nbsp;&amp;nbsp;&amp;nbsp;Inverting a dictionary using zip&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;c&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;d&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(&#39;a&#39;, 1), (&#39;c&#39;, 3), (&#39;b&#39;, 2), (&#39;d&#39;, 4)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(1, &#39;a&#39;), (3, &#39;c&#39;), (2, &#39;b&#39;), (4, &#39;d&#39;)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mi&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;{1: &#39;a&#39;, 2: &#39;b&#39;, 3: &#39;c&#39;, 4: &#39;d&#39;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;flattening-lists&quot;&gt;
&lt;h3&gt;
1.17&amp;nbsp;&amp;nbsp;&amp;nbsp;Flattening lists:&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chain&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;from_iterable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[1, 2, 3, 4, 5, 6]&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[1, 2, 3, 4, 5, 6]&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[1, 2, 3, 4, 5, 6]&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l1&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l2&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[1, 2, 3, 4, 5, 6, 7, 8]&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flatten&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flatten&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flatten&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[1, 2, 3, 4, 5, 6, 7, 8]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
Note: according to Python&#39;s &lt;a class=&quot;reference external&quot; href=&quot;http://docs.python.org/2.7/library/functions.html#sum&quot;&gt;documentation&lt;/a&gt; on &lt;tt class=&quot;docutils literal&quot;&gt;sum&lt;/tt&gt;,
&lt;tt class=&quot;docutils literal&quot;&gt;itertools.chain.from_iterable&lt;/tt&gt; is the preferred method for this.&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;generator-expressions&quot;&gt;
&lt;h3&gt;
1.18&amp;nbsp;&amp;nbsp;&amp;nbsp;Generator expressions&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;9&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2025&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;408&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;dictionary-comprehensions&quot;&gt;
&lt;h3&gt;
1.19&amp;nbsp;&amp;nbsp;&amp;nbsp;Dictionary comprehensions&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;A&#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;{0: &#39;A0&#39;, 1: &#39;A1&#39;, 2: &#39;A2&#39;, 3: &#39;A3&#39;, 4: &#39;A4&#39;, 5: &#39;A5&#39;, 6: &#39;A6&#39;, 7: &#39;A7&#39;, 8: &#39;A8&#39;, 9: &#39;A9&#39;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;inverting-a-dictionary-using-a-dictionary-comprehension&quot;&gt;
&lt;h3&gt;
1.20&amp;nbsp;&amp;nbsp;&amp;nbsp;Inverting a dictionary using a dictionary comprehension&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;c&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;d&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;{&#39;d&#39;: 4, &#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()}&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;{1: &#39;a&#39;, 2: &#39;b&#39;, 3: &#39;c&#39;, 4: &#39;d&#39;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;named-tuples-collections-namedtuple&quot;&gt;
&lt;h3&gt;
1.21&amp;nbsp;&amp;nbsp;&amp;nbsp;Named tuples (&lt;tt class=&quot;docutils literal&quot;&gt;collections.namedtuple&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Point&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;namedtuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;Point&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;y&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Point(x=1.0, y=2.0)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1.0&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2.0&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;inheriting-from-named-tuples&quot;&gt;
&lt;h3&gt;
1.22&amp;nbsp;&amp;nbsp;&amp;nbsp;Inheriting from named tuples:&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;namedtuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;PointBase&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;x&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;y&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;__slots__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;__add__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Point(x=3.0, y=5.0)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;sets-and-set-operations&quot;&gt;
&lt;h3&gt;
1.23&amp;nbsp;&amp;nbsp;&amp;nbsp;Sets and set operations&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;set([1, 2, 3])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;set([3, 4, 5, 6, 7])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;set([1, 2, 3, 4, 5, 6, 7])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;set([3])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;set([1, 2])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;set([4, 5, 6, 7])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;set([1, 2, 4, 5, 6, 7])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;True&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;multisets-and-multiset-operations-collections-counter&quot;&gt;
&lt;h3&gt;
1.24&amp;nbsp;&amp;nbsp;&amp;nbsp;Multisets and multiset operations (&lt;tt class=&quot;docutils literal&quot;&gt;collections.Counter&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Counter({2: 2, 1: 1})&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Counter({2: 2, 3: 1})&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Counter({2: 2, 1: 1, 3: 1})&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Counter({2: 2})&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Counter({2: 4, 1: 1, 3: 1})&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Counter({1: 1})&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Counter({3: 1})&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;most-common-elements-in-an-iterable-collections-counter&quot;&gt;
&lt;h3&gt;
1.25&amp;nbsp;&amp;nbsp;&amp;nbsp;Most common elements in an iterable (&lt;tt class=&quot;docutils literal&quot;&gt;collections.Counter&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Counter({3: 4, 1: 2, 2: 2, 4: 1, 5: 1, 6: 1, 7: 1})&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;most_common&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(3, 4)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;most_common&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[(3, 4), (1, 2), (2, 2)]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;double-ended-queue-collections-deque&quot;&gt;
&lt;h3&gt;
1.26&amp;nbsp;&amp;nbsp;&amp;nbsp;Double-ended queue (&lt;tt class=&quot;docutils literal&quot;&gt;collections.deque&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deque&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;appendleft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extendleft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;deque([6, 5, 2, 1, 3, 4])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;popleft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;6&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;deque([5, 2, 1, 3])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rotate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;deque([2, 1, 3, 5])&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rotate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Q&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;deque([5, 2, 1, 3])&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;double-ended-queue-with-maximum-length-collections-deque&quot;&gt;
&lt;h3&gt;
1.27&amp;nbsp;&amp;nbsp;&amp;nbsp;Double-ended queue with maximum length (&lt;tt class=&quot;docutils literal&quot;&gt;collections.deque&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;last_three&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deque&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;maxlen&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;last_three&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;, &#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last_three&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0, 1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0, 1, 2&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1, 2, 3&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2, 3, 4&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3, 4, 5&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4, 5, 6&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;5, 6, 7&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;6, 7, 8&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;7, 8, 9&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;ordered-dictionaries-collections-ordereddict&quot;&gt;
&lt;h3&gt;
1.28&amp;nbsp;&amp;nbsp;&amp;nbsp;Ordered dictionaries (&lt;tt class=&quot;docutils literal&quot;&gt;collections.OrderedDict&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;, &#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1, 0, 3, 2, 5, 4, 7, 6, 9, 8&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OrderedDict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;, &#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0, 1, 2, 3, 4, 5, 6, 7, 8, 9&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OrderedDict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;, &#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;10, 9, 8, 7, 6, 5, 4, 3, 2, 1&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;default-dictionaries-collections-defaultdict&quot;&gt;
&lt;h3&gt;
1.29&amp;nbsp;&amp;nbsp;&amp;nbsp;Default dictionaries (&lt;tt class=&quot;docutils literal&quot;&gt;collections.defaultdict&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
  File &lt;span class=&quot;nb&quot;&gt;&quot;&amp;lt;stdin&amp;gt;&quot;&lt;/span&gt;, line &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;, in &lt;span class=&quot;n&quot;&gt;&amp;lt;module&amp;gt;&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;KeyError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;&#39;a&#39;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#39;a&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;[default value]&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#39;[default value]&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#39;[default value]&#39;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;section&quot; id=&quot;using-default-dictionaries-to-represent-simple-trees&quot;&gt;
&lt;blockquote&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
1.30&amp;nbsp;&amp;nbsp;&amp;nbsp;Using default dictionaries to represent simple trees&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tree&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tree&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tree&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menu&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;id&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;file&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menu&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;value&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;File&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menu&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menuitems&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;new&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;value&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;New&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menu&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menuitems&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;new&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;onclick&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;new();&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menu&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menuitems&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;open&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;value&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;Open&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menu&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menuitems&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;open&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;onclick&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;open();&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menu&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menuitems&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;close&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;value&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;Close&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menu&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;menuitems&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;close&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;onclick&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;close();&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sort_keys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;indent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;separators&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;,&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;: &#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &quot;menu&quot;: {&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;        &quot;id&quot;: &quot;file&quot;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;        &quot;menuitems&quot;: {&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;            &quot;close&quot;: {&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                &quot;onclick&quot;: &quot;close();&quot;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                &quot;value&quot;: &quot;Close&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;            },&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;            &quot;new&quot;: {&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                &quot;onclick&quot;: &quot;new();&quot;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                &quot;value&quot;: &quot;New&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;            },&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;            &quot;open&quot;: {&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                &quot;onclick&quot;: &quot;open();&quot;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;                &quot;value&quot;: &quot;Open&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;            }&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;        },&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;        &quot;value&quot;: &quot;File&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    }&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
(See &lt;a class=&quot;reference external&quot; href=&quot;https://gist.github.com/hrldcpr/2012250&quot;&gt;https://gist.github.com/hrldcpr/2012250&lt;/a&gt; for more on this.)&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;mapping-objects-to-unique-counting-numbers-collections-defaultdict&quot;&gt;
&lt;h3&gt;
1.31&amp;nbsp;&amp;nbsp;&amp;nbsp;Mapping objects to unique counting numbers (&lt;tt class=&quot;docutils literal&quot;&gt;collections.defaultdict&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;collections&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value_to_numeric_map&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;defaultdict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value_to_numeric_map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value_to_numeric_map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value_to_numeric_map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;c&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value_to_numeric_map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value_to_numeric_map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;largest-and-smallest-elements-heapq-nlargest-and-heapq-nsmallest&quot;&gt;
&lt;h3&gt;
1.32&amp;nbsp;&amp;nbsp;&amp;nbsp;Largest and smallest elements (&lt;tt class=&quot;docutils literal&quot;&gt;heapq.nlargest&lt;/tt&gt; and &lt;tt class=&quot;docutils literal&quot;&gt;heapq.nsmallest&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;randint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heapq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nsmallest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[3, 3, 5, 6, 8]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;heapq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nlargest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[100, 100, 99, 98, 98]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;cartesian-products-itertools-product&quot;&gt;
&lt;h3&gt;
1.33&amp;nbsp;&amp;nbsp;&amp;nbsp;Cartesian products (&lt;tt class=&quot;docutils literal&quot;&gt;itertools.product&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;product&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]):&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 5)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 5)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(3, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(3, 5)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;product&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;repeat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0000&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0001&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0010&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0011&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0100&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0101&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0110&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0111&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1000&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1001&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1010&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1011&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1100&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1101&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1110&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1111&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;combinations-and-combinations-with-replacement-itertools-combinations-and-itertools-combinations-with-replacement&quot;&gt;
&lt;h3&gt;
1.34&amp;nbsp;&amp;nbsp;&amp;nbsp;Combinations and combinations with replacement (&lt;tt class=&quot;docutils literal&quot;&gt;itertools.combinations&lt;/tt&gt; and &lt;tt class=&quot;docutils literal&quot;&gt;itertools.combinations_with_replacement&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;combinations&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;123&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;124&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;125&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;134&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;135&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;145&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;234&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;235&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;245&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;345&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;combinations_with_replacement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;11&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;12&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;13&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;22&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;23&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;33&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;permutations-itertools-permutations&quot;&gt;
&lt;h3&gt;
1.35&amp;nbsp;&amp;nbsp;&amp;nbsp;Permutations (&lt;tt class=&quot;docutils literal&quot;&gt;itertools.permutations&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;permutations&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1234&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1243&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1324&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1342&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1423&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1432&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2134&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2143&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2314&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2341&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2413&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2431&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3124&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3142&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3214&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3241&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3412&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3421&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4123&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4132&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4213&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4231&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4312&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4321&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;chaining-iterables-itertools-chain&quot;&gt;
&lt;h3&gt;
1.36&amp;nbsp;&amp;nbsp;&amp;nbsp;Chaining iterables (&lt;tt class=&quot;docutils literal&quot;&gt;itertools.chain&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;combinations&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;combinations&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 3)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 3)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(3, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2, 3)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 3, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 3, 4)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subset&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chain&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;from_iterable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;combinations&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subset&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1,)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2,)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(3,)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(4,)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 3)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 3)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(3, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2, 3)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 3, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 3, 4)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, 2, 3, 4)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;grouping-rows-by-a-given-key-itertools-groupby&quot;&gt;
&lt;h3&gt;
1.37&amp;nbsp;&amp;nbsp;&amp;nbsp;Grouping rows by a given key (&lt;tt class=&quot;docutils literal&quot;&gt;itertools.groupby&lt;/tt&gt;)&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;operator&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itemgetter&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;itertools&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;contactlenses.csv&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;r&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;infile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;,&#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;infile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rows&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&#39;{: &amp;lt;16}&#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rows&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               myope                   no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               myope                   no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               myope                   yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               myope                   yes                     normal                  hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               hypermetrope            no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               hypermetrope            no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               hypermetrope            yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               hypermetrope            yes                     normal                  hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      myope                   no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      myope                   no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      myope                   yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      myope                   yes                     normal                  hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      hypermetrope            no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      hypermetrope            no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      hypermetrope            yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      hypermetrope            yes                     normal                  none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          myope                   no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          myope                   no                      normal                  none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          myope                   yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          myope                   yes                     normal                  hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          hypermetrope            no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          hypermetrope            no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          hypermetrope            yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          hypermetrope            yes                     normal                  none&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;itemgetter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;itertools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;groupby&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;-----------&#39;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&#39;Group: &#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;print_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;-----------&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Group: hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               myope                   yes                     normal                  hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               hypermetrope            yes                     normal                  hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      myope                   yes                     normal                  hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          myope                   yes                     normal                  hard&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;-----------&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Group: none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               myope                   no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               myope                   yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               hypermetrope            no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               hypermetrope            yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      myope                   no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      myope                   yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      hypermetrope            no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      hypermetrope            yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      hypermetrope            yes                     normal                  none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          myope                   no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          myope                   no                      normal                  none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          myope                   yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          hypermetrope            no                      reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          hypermetrope            yes                     reduced                 none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          hypermetrope            yes                     normal                  none&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;-----------&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Group: soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               myope                   no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;young               hypermetrope            no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      myope                   no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pre-presbyopic      hypermetrope            no                      normal                  soft&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;presbyopic          hypermetrope            no                      normal                  soft&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;start-a-static-http-server-in-any-directory&quot;&gt;
&lt;h3&gt;
1.38&amp;nbsp;&amp;nbsp;&amp;nbsp;Start a static HTTP server in any directory&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;10:26&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;python -m SimpleHTTPServer 5000
Serving HTTP on 0.0.0.0 port 5000 ...
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;learn-the-zen-of-python&quot;&gt;
&lt;h3&gt;
1.39&amp;nbsp;&amp;nbsp;&amp;nbsp;Learn the Zen of Python&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;this&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;The Zen of Python, by Tim Peters&lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;Beautiful is better than ugly.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Explicit is better than implicit.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Simple is better than complex.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Complex is better than complicated.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Flat is better than nested.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Sparse is better than dense.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Readability counts.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Special cases aren&#39;t special enough to break the rules.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Although practicality beats purity.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Errors should never pass silently.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Unless explicitly silenced.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;In the face of ambiguity, refuse the temptation to guess.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;There should be one-- and preferably only one --obvious way to do it.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Although that way may not be obvious at first unless you&#39;re Dutch.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Now is better than never.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Although never is often better than *right* now.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;If the implementation is hard to explain, it&#39;s a bad idea.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;If the implementation is easy to explain, it may be a good idea.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Namespaces are one honking great idea -- let&#39;s do more of those!&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;use-c-style-braces-instead-of-indentation-to-denote-scopes&quot;&gt;
&lt;h3&gt;
1.40&amp;nbsp;&amp;nbsp;&amp;nbsp;Use C-Style Braces Instead of Indentation to Denote Scopes&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;highlight&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;__future__&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;braces&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;br /&gt;
Good Luck Have Fun! &lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/1797132843450528529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/30-python-language-features-and-tricks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/1797132843450528529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/1797132843450528529'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/30-python-language-features-and-tricks.html' title='30 Python Language Features and Tricks You May Not Know About'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3524535260938031835.post-2586069122282404980</id><published>2015-01-15T18:31:00.000-08:00</published><updated>2015-11-24T17:58:32.684-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="tutorial"/><title type='text'>Python Performance Tips</title><content type='html'>Have Been 5 year or may be more :D I used python for create many automation script. In this section I will share something about how to improve performance to speedup python code. This is originally I got from &lt;a href=&quot;http://wiki.python.org/&quot;&gt;wiki.python.org&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
You can only know what makes your program slow after first getting the 
program to give correct results, then running it to see if the correct 
program is slow. &lt;span class=&quot;anchor&quot; id=&quot;line-31&quot;&gt;&lt;/span&gt;When found to 
be slow, profiling can show what parts of the program are consuming most
 of the time. A comprehensive but quick-to-run test suite can then 
ensure that future optimizations don&#39;t change the correctness of your 
program. &lt;span class=&quot;anchor&quot; id=&quot;line-32&quot;&gt;&lt;/span&gt;In short:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Get it right.&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Test it&#39;s right.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Profile if slow.&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Optimise.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Repeat from 2.&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
Certain optimizations amount to good programming style and so should be 
learned as you learn the language. An example would be moving the 
calculation of values that don&#39;t change within a loop, outside of the 
loop.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h2 id=&quot;Choose_the_Right_Data_Structure&quot;&gt;
Choose the Right Data Structure&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-46&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-47&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-48&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
TBD. &lt;span class=&quot;anchor&quot; id=&quot;line-49&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-50&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-51&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Sorting&quot;&gt;
Sorting&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-52&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-53&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-54&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Sorting
 lists of basic Python objects is generally pretty efficient. The sort 
method for lists takes an optional comparison function as an argument 
that can be used to change the sorting behavior. This is quite 
convenient, though it can significantly slow down your sorts, as the 
comparison function will be called many times. In Python 2.4, you should
 use the key argument to the built-in sort instead, which should be the 
fastest way to sort. &lt;span class=&quot;anchor&quot; id=&quot;line-55&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-56&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-57&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Only if you are using older versions of Python (before 2.4) does the following advice from Guido van Rossum apply: &lt;span class=&quot;anchor&quot; id=&quot;line-58&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-59&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-60&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
An
 alternative way to speed up sorts is to construct a list of tuples 
whose first element is a sort key that will sort properly using the 
default comparison, and whose second element is the original list 
element. This is the so-called &lt;a class=&quot;http&quot; href=&quot;http://www.google.com/search?q=Schwartzian+Transform&quot;&gt;Schwartzian Transform&lt;/a&gt;, also known as &lt;a class=&quot;nonexistent&quot; href=&quot;https://wiki.python.org/moin/DecorateSortUndecorate&quot;&gt;DecorateSortUndecorate&lt;/a&gt; (DSU). &lt;span class=&quot;anchor&quot; id=&quot;line-61&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-62&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-63&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Suppose,
 for example, you have a list of tuples that you want to sort by the 
n-th field of each tuple. The following function will do that.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-64&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-65&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-66&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-67&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-68&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-69&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-70&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-71&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-72&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-73&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-74&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-75&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-76&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1&quot;&gt;&lt;/span&gt;def sortby(somelist, n):
&lt;span class=&quot;anchor&quot; id=&quot;line-2&quot;&gt;&lt;/span&gt;    nlist = [(x[n], x) for x in somelist]
&lt;span class=&quot;anchor&quot; id=&quot;line-3&quot;&gt;&lt;/span&gt;    nlist.sort()
&lt;span class=&quot;anchor&quot; id=&quot;line-4&quot;&gt;&lt;/span&gt;    return [val for (key, val) in nlist]&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-77&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-78&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-79&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-80&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Matching the behavior of the current list sort method (sorting in place) is easily achieved as well:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-81&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-82&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-83&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-84&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-85&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-86&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-87&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-88&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-89&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-90&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-91&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-92&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-93&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-94&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-1&quot;&gt;&lt;/span&gt;def sortby_inplace(somelist, n):
&lt;span class=&quot;anchor&quot; id=&quot;line-2-1&quot;&gt;&lt;/span&gt;    somelist[:] = [(x[n], x) for x in somelist]
&lt;span class=&quot;anchor&quot; id=&quot;line-3-1&quot;&gt;&lt;/span&gt;    somelist.sort()
&lt;span class=&quot;anchor&quot; id=&quot;line-4-1&quot;&gt;&lt;/span&gt;    somelist[:] = [val for (key, val) in somelist]
&lt;span class=&quot;anchor&quot; id=&quot;line-5&quot;&gt;&lt;/span&gt;    return&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-95&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-96&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-97&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-98&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Here&#39;s an example use:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-99&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-100&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-101&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-102&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-103&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-104&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-105&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-106&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-107&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-108&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-109&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-110&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-111&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-112&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-113&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-114&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-115&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-116&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-117&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-118&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-119&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-2&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; somelist = [(1, 2, &#39;def&#39;), (2, -4, &#39;ghi&#39;), (3, 6, &#39;abc&#39;)]
&lt;span class=&quot;anchor&quot; id=&quot;line-2-2&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; somelist.sort()
&lt;span class=&quot;anchor&quot; id=&quot;line-3-2&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; somelist
&lt;span class=&quot;anchor&quot; id=&quot;line-4-2&quot;&gt;&lt;/span&gt;[(1, 2, &#39;def&#39;), (2, -4, &#39;ghi&#39;), (3, 6, &#39;abc&#39;)]
&lt;span class=&quot;anchor&quot; id=&quot;line-5-1&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; nlist = sortby(somelist, 2)
&lt;span class=&quot;anchor&quot; id=&quot;line-6&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; sortby_inplace(somelist, 2)
&lt;span class=&quot;anchor&quot; id=&quot;line-7&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; nlist == somelist
&lt;span class=&quot;anchor&quot; id=&quot;line-8&quot;&gt;&lt;/span&gt;True
&lt;span class=&quot;anchor&quot; id=&quot;line-9&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; nlist = sortby(somelist, 1)
&lt;span class=&quot;anchor&quot; id=&quot;line-10&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; sortby_inplace(somelist, 1)
&lt;span class=&quot;anchor&quot; id=&quot;line-11&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; nlist == somelist
&lt;span class=&quot;anchor&quot; id=&quot;line-12&quot;&gt;&lt;/span&gt;True&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-120&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-121&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-122&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-123&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
From Tim Delaney &lt;span class=&quot;anchor&quot; id=&quot;line-124&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-125&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-126&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
From Python 2.3 sort is guaranteed to be stable. &lt;span class=&quot;anchor&quot; id=&quot;line-127&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-128&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-129&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
(to be precise, it&#39;s stable in CPython 2.3, and guaranteed to be stable in Python 2.4) &lt;span class=&quot;anchor&quot; id=&quot;line-130&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-131&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-132&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Python 2.4 adds an optional key parameter which makes the transform a lot easier to use:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-133&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-134&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-135&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-136&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-137&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-138&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-139&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-140&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-141&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-142&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-143&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-144&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-145&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-146&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-147&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-3&quot;&gt;&lt;/span&gt;# E.g. n = 1
&lt;span class=&quot;anchor&quot; id=&quot;line-2-3&quot;&gt;&lt;/span&gt;n = 1
&lt;span class=&quot;anchor&quot; id=&quot;line-3-3&quot;&gt;&lt;/span&gt;import operator
&lt;span class=&quot;anchor&quot; id=&quot;line-4-3&quot;&gt;&lt;/span&gt;nlist.sort(key=operator.itemgetter(n))
&lt;span class=&quot;anchor&quot; id=&quot;line-5-2&quot;&gt;&lt;/span&gt;# use sorted() if you don&#39;t want to sort in-place:
&lt;span class=&quot;anchor&quot; id=&quot;line-6-1&quot;&gt;&lt;/span&gt;# sortedlist = sorted(nlist, key=operator.itemgetter(n))&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-148&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-149&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-150&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-151&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Note that the original item is never used for sorting, only the returned key - this is equivalent to doing:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-152&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-153&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-154&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-155&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-156&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-157&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-158&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-159&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-160&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-161&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-162&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-163&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-164&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-165&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-4&quot;&gt;&lt;/span&gt;# E.g. n = 1
&lt;span class=&quot;anchor&quot; id=&quot;line-2-4&quot;&gt;&lt;/span&gt;n = 1
&lt;span class=&quot;anchor&quot; id=&quot;line-3-4&quot;&gt;&lt;/span&gt;nlist = [(x[n], i, x) for (i, x) in enumerate(nlist)]
&lt;span class=&quot;anchor&quot; id=&quot;line-4-4&quot;&gt;&lt;/span&gt;nlist.sort()
&lt;span class=&quot;anchor&quot; id=&quot;line-5-3&quot;&gt;&lt;/span&gt;nlist = [val for (key, index, val) in nlist]&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-166&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-167&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-168&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-169&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;String_Concatenation&quot;&gt;
String Concatenation&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-170&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-171&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-172&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-173&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-174&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-175&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-176&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
The
 accuracy of this section is disputed with respect to later versions of 
Python. In CPython 2.5, string concatenation is fairly fast, although 
this may not apply likewise to other Python implementations. See &lt;a href=&quot;https://wiki.python.org/moin/ConcatenationTestCode&quot;&gt;ConcatenationTestCode&lt;/a&gt; for a discussion. &lt;span class=&quot;anchor&quot; id=&quot;line-177&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-178&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-179&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-180&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-181&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Strings
 in Python are immutable. This fact frequently sneaks up and bites 
novice Python programmers on the rump. Immutability confers some 
advantages and disadvantages. In the plus column, strings can be used as
 keys in dictionaries and individual copies can be shared among multiple
 variable bindings. (Python automatically shares one- and two-character 
strings.) In the minus column, you can&#39;t say something like, &quot;change all
 the &#39;a&#39;s to &#39;b&#39;s&quot; in any given string. Instead, you have to create a 
new string with the desired properties. This continual copying can lead 
to significant inefficiencies in Python programs. &lt;span class=&quot;anchor&quot; id=&quot;line-182&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-183&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-184&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Avoid this&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-185&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-186&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-187&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-188&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-189&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-190&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-191&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-192&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-193&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-194&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-195&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-196&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-5&quot;&gt;&lt;/span&gt;s = &quot;&quot;
&lt;span class=&quot;anchor&quot; id=&quot;line-2-5&quot;&gt;&lt;/span&gt;for substring in list:
&lt;span class=&quot;anchor&quot; id=&quot;line-3-5&quot;&gt;&lt;/span&gt;    s += substring&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-197&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-198&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-199&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-200&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
Use &lt;tt&gt;s&amp;nbsp;=&amp;nbsp;&quot;&quot;.join(list)&lt;/tt&gt;
 instead. The former is a very common and catastrophic mistake when 
building large strings. Similarly, if you are generating bits of a 
string sequentially instead of:&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-201&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-202&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-203&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-204&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-205&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-206&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-207&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-208&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-209&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-210&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-211&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-212&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-6&quot;&gt;&lt;/span&gt;s = &quot;&quot;
&lt;span class=&quot;anchor&quot; id=&quot;line-2-6&quot;&gt;&lt;/span&gt;for x in list:
&lt;span class=&quot;anchor&quot; id=&quot;line-3-6&quot;&gt;&lt;/span&gt;    s += some_function(x)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-213&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-214&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-215&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-216&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
use&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-217&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-218&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-219&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-220&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-221&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-222&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-223&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-224&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-225&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-226&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-227&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-7&quot;&gt;&lt;/span&gt;slist = [some_function(elt) for elt in somelist]
&lt;span class=&quot;anchor&quot; id=&quot;line-2-7&quot;&gt;&lt;/span&gt;s = &quot;&quot;.join(slist)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-228&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-229&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-230&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-231&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Avoid:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-232&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-233&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-234&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-235&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-236&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-237&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-238&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-239&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-240&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-241&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-8&quot;&gt;&lt;/span&gt;out = &quot;&amp;lt;html&amp;gt;&quot; + head + prologue + query + tail + &quot;&amp;lt;/html&amp;gt;&quot;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-242&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-243&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-244&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-245&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Instead, use&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-246&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-247&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-248&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-249&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-250&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-252&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-253&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-254&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-255&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-9&quot;&gt;&lt;/span&gt;out = &quot;&amp;lt;html&amp;gt;%s%s%s%s&amp;lt;/html&amp;gt;&quot; % (head, prologue, query, tail)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-256&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-257&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-258&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-259&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Even
 better, for readability (this has nothing to do with efficiency other 
than yours as a programmer), use dictionary substitution:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-260&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-261&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-262&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-263&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-264&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-265&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-266&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-267&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-268&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-269&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-10&quot;&gt;&lt;/span&gt;out = &quot;&amp;lt;html&amp;gt;%(head)s%(prologue)s%(query)s%(tail)s&amp;lt;/html&amp;gt;&quot; % locals()&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-270&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-271&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-272&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-273&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
This
 last two are going to be much faster, especially when piled up over 
many CGI script executions, and easier to modify to boot. In addition, 
the slow way of doing things got slower in Python 2.0 with the addition 
of rich comparisons to the language. It now takes the Python virtual 
machine a lot longer to figure out how to concatenate two strings. 
(Don&#39;t forget that Python does all method lookup at runtime.) &lt;span class=&quot;anchor&quot; id=&quot;line-274&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-275&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-276&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Loops&quot;&gt;
Loops&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-277&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-278&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-279&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
Python supports a couple of looping constructs. The &lt;tt&gt;for&lt;/tt&gt;
 statement is most commonly used. It loops over the elements of a 
sequence, assigning each to the loop variable. If the body of your loop 
is simple, the interpreter overhead of the &lt;tt&gt;for&lt;/tt&gt; loop itself can be a substantial amount of the overhead. This is where the &lt;a class=&quot;http&quot; href=&quot;http://www.python.org/doc/lib/built-in-funcs.html&quot;&gt;map&lt;/a&gt; function is handy. You can think of &lt;tt&gt;map&lt;/tt&gt; as a &lt;tt&gt;for&lt;/tt&gt; moved into C code. The only restriction is that the &quot;loop body&quot; of &lt;tt&gt;map&lt;/tt&gt;
 must be a function call. Besides the syntactic benefit of list 
comprehensions, they are often as fast or faster than equivalent use of &lt;tt&gt;map&lt;/tt&gt;. &lt;span class=&quot;anchor&quot; id=&quot;line-280&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-281&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-282&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Here&#39;s a straightforward example. Instead of looping over a list of words and converting them to upper case:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-283&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-284&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-285&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-286&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-287&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-288&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-289&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-290&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-291&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-292&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-293&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-294&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-11&quot;&gt;&lt;/span&gt;newlist = []
&lt;span class=&quot;anchor&quot; id=&quot;line-2-8&quot;&gt;&lt;/span&gt;for word in oldlist:
&lt;span class=&quot;anchor&quot; id=&quot;line-3-7&quot;&gt;&lt;/span&gt;    newlist.append(word.upper())&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-295&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-296&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-297&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-298&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
you can use &lt;tt&gt;map&lt;/tt&gt; to push the loop from the interpreter into compiled C code:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-299&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-300&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-301&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-302&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-303&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-304&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-305&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-306&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-307&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-308&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-12&quot;&gt;&lt;/span&gt;newlist = map(str.upper, oldlist)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-309&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-310&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-311&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-312&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
List
 comprehensions were added to Python in version 2.0 as well. They 
provide a syntactically more compact and more efficient way of writing 
the above for loop:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-313&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-314&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-315&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-316&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-317&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-318&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-319&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-320&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-321&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-322&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-13&quot;&gt;&lt;/span&gt;newlist = [s.upper() for s in oldlist]&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-323&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-324&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-325&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-326&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
Generator expressions were added to Python in version 2.4. They function more-or-less like list comprehensions or &lt;tt&gt;map&lt;/tt&gt;
 but avoid the overhead of generating the entire list at once. Instead, 
they return a generator object which can be iterated over bit-by-bit: &lt;span class=&quot;anchor&quot; id=&quot;line-327&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-328&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-329&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-330&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-331&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-332&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-333&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-334&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-335&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-336&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-14&quot;&gt;&lt;/span&gt;iterator = (s.upper() for s in oldlist)&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-337&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-338&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-339&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-340&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Which
 method is appropriate will depend on what version of Python you&#39;re 
using and the characteristics of the data you are manipulating. &lt;span class=&quot;anchor&quot; id=&quot;line-341&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-342&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-343&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
Guido van Rossum wrote a much more detailed (and succinct) examination of &lt;a class=&quot;http&quot; href=&quot;http://www.python.org/doc/essays/list2str/&quot;&gt;loop optimization&lt;/a&gt; that is definitely worth reading. &lt;span class=&quot;anchor&quot; id=&quot;line-344&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-345&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-346&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Avoiding_dots...&quot;&gt;
Avoiding dots...&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-347&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-348&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-349&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
Suppose you can&#39;t use &lt;tt&gt;map&lt;/tt&gt; or a list comprehension? You may be stuck with the for loop. The for loop example has another inefficiency. Both &lt;tt&gt;newlist.append&lt;/tt&gt; and &lt;tt&gt;word.upper&lt;/tt&gt; are function references that are reevaluated each time through the loop. The original loop can be replaced with:&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-350&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-351&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-352&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-353&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-354&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-355&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-356&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-357&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-358&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-359&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-360&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-361&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-362&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-363&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-15&quot;&gt;&lt;/span&gt;upper = str.upper
&lt;span class=&quot;anchor&quot; id=&quot;line-2-9&quot;&gt;&lt;/span&gt;newlist = []
&lt;span class=&quot;anchor&quot; id=&quot;line-3-8&quot;&gt;&lt;/span&gt;append = newlist.append
&lt;span class=&quot;anchor&quot; id=&quot;line-4-5&quot;&gt;&lt;/span&gt;for word in oldlist:
&lt;span class=&quot;anchor&quot; id=&quot;line-5-4&quot;&gt;&lt;/span&gt;    append(upper(word))&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-364&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-365&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-366&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-367&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
This
 technique should be used with caution. It gets more difficult to 
maintain if the loop is large. Unless you are intimately familiar with 
that piece of code you will find yourself scanning up to check the 
definitions of &lt;tt&gt;append&lt;/tt&gt; and &lt;tt&gt;upper&lt;/tt&gt;. &lt;span class=&quot;anchor&quot; id=&quot;line-368&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-369&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-370&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Local_Variables&quot;&gt;
Local Variables&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-371&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-372&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-373&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
The final speedup available to us for the non-&lt;tt&gt;map&lt;/tt&gt; version of the &lt;tt&gt;for&lt;/tt&gt; loop is to use local variables wherever possible. If the above loop is cast as a function, &lt;tt&gt;append&lt;/tt&gt; and &lt;tt&gt;upper&lt;/tt&gt; become local variables. Python accesses local variables much more efficiently than global variables.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-374&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-375&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-376&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-377&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-378&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-379&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-380&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-381&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-382&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-383&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-384&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-385&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-386&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-387&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-388&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-389&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-16&quot;&gt;&lt;/span&gt;def func():
&lt;span class=&quot;anchor&quot; id=&quot;line-2-10&quot;&gt;&lt;/span&gt;    upper = str.upper
&lt;span class=&quot;anchor&quot; id=&quot;line-3-9&quot;&gt;&lt;/span&gt;    newlist = []
&lt;span class=&quot;anchor&quot; id=&quot;line-4-6&quot;&gt;&lt;/span&gt;    append = newlist.append
&lt;span class=&quot;anchor&quot; id=&quot;line-5-5&quot;&gt;&lt;/span&gt;    for word in oldlist:
&lt;span class=&quot;anchor&quot; id=&quot;line-6-2&quot;&gt;&lt;/span&gt;        append(upper(word))
&lt;span class=&quot;anchor&quot; id=&quot;line-7-1&quot;&gt;&lt;/span&gt;    return newlist&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-390&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-391&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-392&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-393&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
At
 the time I originally wrote this I was using a 100MHz Pentium running 
BSDI. I got the following times for converting the list of words in &lt;tt&gt;/usr/share/dict/words&lt;/tt&gt; (38,470 words at that time) to upper case:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-394&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-395&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-396&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-397&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-398&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-399&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-400&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-401&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-402&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-403&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-404&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-405&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-17&quot;&gt;&lt;/span&gt;Version Time (seconds)
&lt;span class=&quot;anchor&quot; id=&quot;line-2-11&quot;&gt;&lt;/span&gt;Basic loop 3.47
&lt;span class=&quot;anchor&quot; id=&quot;line-3-10&quot;&gt;&lt;/span&gt;Eliminate dots 2.45
&lt;span class=&quot;anchor&quot; id=&quot;line-4-7&quot;&gt;&lt;/span&gt;Local variable &amp;amp; no dots 1.79
&lt;span class=&quot;anchor&quot; id=&quot;line-5-6&quot;&gt;&lt;/span&gt;Using map function 0.54&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-406&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-407&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-408&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Initializing_Dictionary_Elements&quot;&gt;
Initializing Dictionary Elements&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-409&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-410&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-411&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Suppose
 you are building a dictionary of word frequencies and you&#39;ve already 
broken your text up into a list of words. You might execute something 
like:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-412&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-413&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-414&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-415&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-416&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-417&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-418&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-419&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-420&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-421&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-422&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-423&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-424&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-425&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-18&quot;&gt;&lt;/span&gt;wdict = {}
&lt;span class=&quot;anchor&quot; id=&quot;line-2-12&quot;&gt;&lt;/span&gt;for word in words:
&lt;span class=&quot;anchor&quot; id=&quot;line-3-11&quot;&gt;&lt;/span&gt;    if word not in wdict:
&lt;span class=&quot;anchor&quot; id=&quot;line-4-8&quot;&gt;&lt;/span&gt;        wdict[word] = 0
&lt;span class=&quot;anchor&quot; id=&quot;line-5-7&quot;&gt;&lt;/span&gt;    wdict[word] += 1&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-426&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-427&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-428&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-429&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
Except for the first time, each time a word is seen the &lt;tt&gt;if&lt;/tt&gt;
 statement&#39;s test fails. If you are counting a large number of words, 
many will probably occur multiple times. In a situation where the 
initialization of a value is only going to occur once and the 
augmentation of that value will occur many times it is cheaper to use a &lt;tt&gt;try&lt;/tt&gt; statement:&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-430&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-431&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-432&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-433&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-434&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-435&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-436&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-437&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-438&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-439&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-440&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-441&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-442&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-443&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-444&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-19&quot;&gt;&lt;/span&gt;wdict = {}
&lt;span class=&quot;anchor&quot; id=&quot;line-2-13&quot;&gt;&lt;/span&gt;for word in words:
&lt;span class=&quot;anchor&quot; id=&quot;line-3-12&quot;&gt;&lt;/span&gt;    try:
&lt;span class=&quot;anchor&quot; id=&quot;line-4-9&quot;&gt;&lt;/span&gt;        wdict[word] += 1
&lt;span class=&quot;anchor&quot; id=&quot;line-5-8&quot;&gt;&lt;/span&gt;    except KeyError:
&lt;span class=&quot;anchor&quot; id=&quot;line-6-3&quot;&gt;&lt;/span&gt;        wdict[word] = 1&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-445&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-446&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-447&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-448&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
It&#39;s important to catch the expected &lt;a href=&quot;https://wiki.python.org/moin/KeyError&quot;&gt;KeyError&lt;/a&gt; exception, and not have a default &lt;tt&gt;except&lt;/tt&gt; clause to avoid trying to recover from an exception you really can&#39;t handle by the statement(s) in the &lt;tt&gt;try&lt;/tt&gt; clause. &lt;span class=&quot;anchor&quot; id=&quot;line-449&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-450&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-451&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
A
 third alternative became available with the release of Python 2.x. 
Dictionaries now have a get() method which will return a default value 
if the desired key isn&#39;t found in the dictionary. This simplifies the 
loop:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-452&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-453&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-454&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-455&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-456&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-457&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-458&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-459&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-460&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-461&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-462&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-463&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-464&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-20&quot;&gt;&lt;/span&gt;wdict = {}
&lt;span class=&quot;anchor&quot; id=&quot;line-2-14&quot;&gt;&lt;/span&gt;get = wdict.get
&lt;span class=&quot;anchor&quot; id=&quot;line-3-13&quot;&gt;&lt;/span&gt;for word in words:
&lt;span class=&quot;anchor&quot; id=&quot;line-4-10&quot;&gt;&lt;/span&gt;    wdict[word] = get(word, 0) + 1&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-465&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-466&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-467&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-468&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
There were clear situations where one 
of the first two approaches was faster. It seems that all three 
approaches now exhibit similar performance (within about 10% of each 
other), more or less independent of the properties of the list of words.
 &lt;span class=&quot;anchor&quot; id=&quot;line-469&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-470&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-471&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
Also, if the value stored in the dictionary is an object or a (mutable) list, you could also use the &lt;tt&gt;dict.setdefault&lt;/tt&gt; method, e.g.&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-472&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-473&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-474&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-475&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-476&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-477&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-478&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-479&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-480&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-481&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-21&quot;&gt;&lt;/span&gt;   4     wdict.setdefault(key, []).append(new_element)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-482&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-483&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-484&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-485&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
You
 might think that this avoids having to look up the key twice. It 
actually doesn&#39;t (even in python 3.0), but at least the double lookup is
 performed in C. &lt;span class=&quot;anchor&quot; id=&quot;line-486&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-487&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-488&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
Another option is to use the &lt;a class=&quot;http&quot; href=&quot;http://docs.python.org/py3k/library/collections.html#collections.defaultdict&quot;&gt;defaultdict&lt;/a&gt; class:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-489&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-490&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-491&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-492&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-493&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-494&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-495&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-496&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-497&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-498&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-499&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-500&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-501&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-502&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-503&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-22&quot;&gt;&lt;/span&gt;from collections import defaultdict
&lt;span class=&quot;anchor&quot; id=&quot;line-2-15&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-3-14&quot;&gt;&lt;/span&gt;wdict = defaultdict(int)
&lt;span class=&quot;anchor&quot; id=&quot;line-4-11&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-5-9&quot;&gt;&lt;/span&gt;for word in words:
&lt;span class=&quot;anchor&quot; id=&quot;line-6-4&quot;&gt;&lt;/span&gt;    wdict[word] += 1&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-504&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-505&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-506&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-507&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Import_Statement_Overhead&quot;&gt;
Import Statement Overhead&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-508&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-509&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-510&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;tt&gt;import&lt;/tt&gt;
 statements can be executed just about anywhere. It&#39;s often useful to 
place them inside functions to restrict their visibility and/or reduce 
initial startup time. Although Python&#39;s interpreter is optimized to not 
import the same module multiple times, repeatedly executing an import 
statement can seriously affect performance in some circumstances. &lt;span class=&quot;anchor&quot; id=&quot;line-511&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-512&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-513&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
Consider the following two snippets of code (originally from Greg &lt;a class=&quot;nonexistent&quot; href=&quot;https://wiki.python.org/moin/McFarlane&quot;&gt;McFarlane&lt;/a&gt;, I believe - I found it unattributed in a comp.lang.python &lt;a class=&quot;mailto&quot; href=&quot;mailto:python-list@python.org&quot;&gt;python-list@python.org&lt;/a&gt; posting and later attributed to him in another source):&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-514&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-515&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-516&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-517&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-518&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-519&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-520&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-521&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-522&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-523&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-524&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-525&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-526&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-527&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-528&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-23&quot;&gt;&lt;/span&gt;def doit1():
&lt;span class=&quot;anchor&quot; id=&quot;line-2-16&quot;&gt;&lt;/span&gt;    import string ###### import statement inside function
&lt;span class=&quot;anchor&quot; id=&quot;line-3-15&quot;&gt;&lt;/span&gt;    string.lower(&#39;Python&#39;)
&lt;span class=&quot;anchor&quot; id=&quot;line-4-12&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-5-10&quot;&gt;&lt;/span&gt;for num in range(100000):
&lt;span class=&quot;anchor&quot; id=&quot;line-6-5&quot;&gt;&lt;/span&gt;    doit1()&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-529&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-530&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-531&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-532&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
or:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-533&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-534&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-535&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-536&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-537&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-538&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-539&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-540&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-541&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-542&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-543&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-544&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-545&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-546&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-547&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-24&quot;&gt;&lt;/span&gt;import string ###### import statement outside function
&lt;span class=&quot;anchor&quot; id=&quot;line-2-17&quot;&gt;&lt;/span&gt;def doit2():
&lt;span class=&quot;anchor&quot; id=&quot;line-3-16&quot;&gt;&lt;/span&gt;    string.lower(&#39;Python&#39;)
&lt;span class=&quot;anchor&quot; id=&quot;line-4-13&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-5-11&quot;&gt;&lt;/span&gt;for num in range(100000):
&lt;span class=&quot;anchor&quot; id=&quot;line-6-6&quot;&gt;&lt;/span&gt;    doit2()&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-548&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-549&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-550&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-551&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;tt&gt;doit2&lt;/tt&gt; will run much faster than &lt;tt&gt;doit1&lt;/tt&gt;, even though the reference to the string module is global in &lt;tt&gt;doit2&lt;/tt&gt;. Here&#39;s a Python interpreter session run using Python 2.3 and the new &lt;tt&gt;timeit&lt;/tt&gt; module, which shows how much faster the second is than the first:&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-552&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-553&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-554&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-555&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-556&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-557&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-558&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-559&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-560&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-561&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-562&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-563&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-564&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-565&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-566&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-567&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-568&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-569&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-570&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-571&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-572&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-573&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-574&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-575&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-25&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; def doit1():
&lt;span class=&quot;anchor&quot; id=&quot;line-2-18&quot;&gt;&lt;/span&gt;... import string
&lt;span class=&quot;anchor&quot; id=&quot;line-3-17&quot;&gt;&lt;/span&gt;... string.lower(&#39;Python&#39;)
&lt;span class=&quot;anchor&quot; id=&quot;line-4-14&quot;&gt;&lt;/span&gt;...
&lt;span class=&quot;anchor&quot; id=&quot;line-5-12&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; import string
&lt;span class=&quot;anchor&quot; id=&quot;line-6-7&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; def doit2():
&lt;span class=&quot;anchor&quot; id=&quot;line-7-2&quot;&gt;&lt;/span&gt;... string.lower(&#39;Python&#39;)
&lt;span class=&quot;anchor&quot; id=&quot;line-8-1&quot;&gt;&lt;/span&gt;...
&lt;span class=&quot;anchor&quot; id=&quot;line-9-1&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; import timeit
&lt;span class=&quot;anchor&quot; id=&quot;line-10-1&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; t = timeit.Timer(setup=&#39;from __main__ import doit1&#39;, stmt=&#39;doit1()&#39;)
&lt;span class=&quot;anchor&quot; id=&quot;line-11-1&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; t.timeit()
&lt;span class=&quot;anchor&quot; id=&quot;line-12-1&quot;&gt;&lt;/span&gt;11.479144930839539
&lt;span class=&quot;anchor&quot; id=&quot;line-13&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; t = timeit.Timer(setup=&#39;from __main__ import doit2&#39;, stmt=&#39;doit2()&#39;)
&lt;span class=&quot;anchor&quot; id=&quot;line-14&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; t.timeit()
&lt;span class=&quot;anchor&quot; id=&quot;line-15&quot;&gt;&lt;/span&gt;4.6661689281463623&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-576&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-577&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-578&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-579&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
String
 methods were introduced to the language in Python 2.0. These provide a 
version that avoids the import completely and runs even faster:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-580&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-581&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-582&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-583&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-584&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-585&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-586&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-587&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-588&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-589&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-590&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-591&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-592&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-593&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-26&quot;&gt;&lt;/span&gt;def doit3():
&lt;span class=&quot;anchor&quot; id=&quot;line-2-19&quot;&gt;&lt;/span&gt;    &#39;Python&#39;.lower()
&lt;span class=&quot;anchor&quot; id=&quot;line-3-18&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-4-15&quot;&gt;&lt;/span&gt;for num in range(100000):
&lt;span class=&quot;anchor&quot; id=&quot;line-5-13&quot;&gt;&lt;/span&gt;    doit3()&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-594&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-595&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-596&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-597&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
Here&#39;s the proof from &lt;tt&gt;timeit&lt;/tt&gt;:&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-598&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-599&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-600&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-602&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-603&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-604&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-605&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-606&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-607&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-608&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-609&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-610&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-611&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-612&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-27&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; def doit3():
&lt;span class=&quot;anchor&quot; id=&quot;line-2-20&quot;&gt;&lt;/span&gt;... &#39;Python&#39;.lower()
&lt;span class=&quot;anchor&quot; id=&quot;line-3-19&quot;&gt;&lt;/span&gt;...
&lt;span class=&quot;anchor&quot; id=&quot;line-4-16&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; t = timeit.Timer(setup=&#39;from __main__ import doit3&#39;, stmt=&#39;doit3()&#39;)
&lt;span class=&quot;anchor&quot; id=&quot;line-5-14&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; t.timeit()
&lt;span class=&quot;anchor&quot; id=&quot;line-6-8&quot;&gt;&lt;/span&gt;2.5606080293655396&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-613&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-614&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-615&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-616&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
The above example is obviously a bit contrived, but the general principle holds. &lt;span class=&quot;anchor&quot; id=&quot;line-617&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-618&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-619&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Note
 that putting an import in a function can speed up the initial loading 
of the module, especially if the imported module might not be required. 
This is generally a case of a &quot;lazy&quot; optimization -- avoiding work 
(importing a module, which can be very expensive) until you are sure it 
is required. &lt;span class=&quot;anchor&quot; id=&quot;line-620&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-621&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-622&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
This
 is only a significant saving in cases where the module wouldn&#39;t have 
been imported at all (from any module) -- if the module is already 
loaded (as will be the case for many standard modules, like &lt;tt&gt;string&lt;/tt&gt; or &lt;tt&gt;re&lt;/tt&gt;), avoiding an import doesn&#39;t save you anything. To see what modules are loaded in the system look in &lt;tt&gt;sys.modules&lt;/tt&gt;. &lt;span class=&quot;anchor&quot; id=&quot;line-623&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-624&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-625&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
A good way to do lazy imports is:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-626&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-627&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-628&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-629&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-630&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-631&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-632&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-633&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-634&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-635&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-636&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-637&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-638&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-639&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-640&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-641&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-28&quot;&gt;&lt;/span&gt;email = None
&lt;span class=&quot;anchor&quot; id=&quot;line-2-21&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-3-20&quot;&gt;&lt;/span&gt;def parse_email():
&lt;span class=&quot;anchor&quot; id=&quot;line-4-17&quot;&gt;&lt;/span&gt;    global email
&lt;span class=&quot;anchor&quot; id=&quot;line-5-15&quot;&gt;&lt;/span&gt;    if email is None:
&lt;span class=&quot;anchor&quot; id=&quot;line-6-9&quot;&gt;&lt;/span&gt;        import email
&lt;span class=&quot;anchor&quot; id=&quot;line-7-3&quot;&gt;&lt;/span&gt;    ...&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-642&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-643&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-644&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-645&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
This way the &lt;tt&gt;email&lt;/tt&gt; module will only be imported once, on the first invocation of &lt;tt&gt;parse_email()&lt;/tt&gt;. &lt;span class=&quot;anchor&quot; id=&quot;line-646&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-647&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-648&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Data_Aggregation&quot;&gt;
Data Aggregation&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-649&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-650&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-651&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Function
 call overhead in Python is relatively high, especially compared with 
the execution speed of a builtin function. This strongly suggests that 
where appropriate, functions should handle data aggregates. Here&#39;s a 
contrived example written in Python.&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-652&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-653&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-654&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-655&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-656&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-657&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-658&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-659&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-660&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-661&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-662&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-663&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-664&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-665&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-666&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-667&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-668&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-669&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-670&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-671&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-672&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-29&quot;&gt;&lt;/span&gt;import time
&lt;span class=&quot;anchor&quot; id=&quot;line-2-22&quot;&gt;&lt;/span&gt;x = 0
&lt;span class=&quot;anchor&quot; id=&quot;line-3-21&quot;&gt;&lt;/span&gt;def doit1(i):
&lt;span class=&quot;anchor&quot; id=&quot;line-4-18&quot;&gt;&lt;/span&gt;    global x
&lt;span class=&quot;anchor&quot; id=&quot;line-5-16&quot;&gt;&lt;/span&gt;    x = x + i
&lt;span class=&quot;anchor&quot; id=&quot;line-6-10&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-7-4&quot;&gt;&lt;/span&gt;list = range(100000)
&lt;span class=&quot;anchor&quot; id=&quot;line-8-2&quot;&gt;&lt;/span&gt;t = time.time()
&lt;span class=&quot;anchor&quot; id=&quot;line-9-2&quot;&gt;&lt;/span&gt;for i in list:
&lt;span class=&quot;anchor&quot; id=&quot;line-10-2&quot;&gt;&lt;/span&gt;    doit1(i)
&lt;span class=&quot;anchor&quot; id=&quot;line-11-2&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-12-2&quot;&gt;&lt;/span&gt;print &quot;%.3f&quot; % (time.time()-t)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-673&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-674&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-675&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-676&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
vs.&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-677&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-678&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-679&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-680&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-681&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-682&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-683&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-684&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-685&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-686&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-687&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-688&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-689&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-690&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-691&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-692&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-693&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-694&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-695&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-696&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-30&quot;&gt;&lt;/span&gt;import time
&lt;span class=&quot;anchor&quot; id=&quot;line-2-23&quot;&gt;&lt;/span&gt;x = 0
&lt;span class=&quot;anchor&quot; id=&quot;line-3-22&quot;&gt;&lt;/span&gt;def doit2(list):
&lt;span class=&quot;anchor&quot; id=&quot;line-4-19&quot;&gt;&lt;/span&gt;    global x
&lt;span class=&quot;anchor&quot; id=&quot;line-5-17&quot;&gt;&lt;/span&gt;    for i in list:
&lt;span class=&quot;anchor&quot; id=&quot;line-6-11&quot;&gt;&lt;/span&gt;        x = x + i
&lt;span class=&quot;anchor&quot; id=&quot;line-7-5&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-8-3&quot;&gt;&lt;/span&gt;list = range(100000)
&lt;span class=&quot;anchor&quot; id=&quot;line-9-3&quot;&gt;&lt;/span&gt;t = time.time()
&lt;span class=&quot;anchor&quot; id=&quot;line-10-3&quot;&gt;&lt;/span&gt;doit2(list)
&lt;span class=&quot;anchor&quot; id=&quot;line-11-3&quot;&gt;&lt;/span&gt;print &quot;%.3f&quot; % (time.time()-t)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-697&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-698&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-699&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-700&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Here&#39;s the proof in the pudding using an interactive session:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-701&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-702&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-703&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-704&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-705&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-706&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-707&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-708&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-709&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-710&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-711&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-712&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-713&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-714&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-715&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-716&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-717&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-718&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-719&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-31&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; t = time.time()
&lt;span class=&quot;anchor&quot; id=&quot;line-2-24&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; for i in list:
&lt;span class=&quot;anchor&quot; id=&quot;line-3-23&quot;&gt;&lt;/span&gt;... doit1(i)
&lt;span class=&quot;anchor&quot; id=&quot;line-4-20&quot;&gt;&lt;/span&gt;...
&lt;span class=&quot;anchor&quot; id=&quot;line-5-18&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; print &quot;%.3f&quot; % (time.time()-t)
&lt;span class=&quot;anchor&quot; id=&quot;line-6-12&quot;&gt;&lt;/span&gt;0.758
&lt;span class=&quot;anchor&quot; id=&quot;line-7-6&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; t = time.time()
&lt;span class=&quot;anchor&quot; id=&quot;line-8-4&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; doit2(list)
&lt;span class=&quot;anchor&quot; id=&quot;line-9-4&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt;&amp;gt; print &quot;%.3f&quot; % (time.time()-t)
&lt;span class=&quot;anchor&quot; id=&quot;line-10-4&quot;&gt;&lt;/span&gt;0.204&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-720&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-721&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-722&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-723&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
Even written in Python, the second example runs about four times faster than the first. Had &lt;tt&gt;doit&lt;/tt&gt; been written in C the difference would likely have been even greater (exchanging a Python &lt;tt&gt;for&lt;/tt&gt; loop for a C &lt;tt&gt;for&lt;/tt&gt; loop as well as removing most of the function calls). &lt;span class=&quot;anchor&quot; id=&quot;line-724&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-725&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-726&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Doing_Stuff_Less_Often&quot;&gt;
Doing Stuff Less Often&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-727&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-728&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-729&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
The
 Python interpreter performs some periodic checks. In particular, it 
decides whether or not to let another thread run and whether or not to 
run a pending call (typically a call established by a signal handler). 
Most of the time there&#39;s nothing to do, so performing these checks each 
pass around the interpreter loop can slow things down. There is a 
function in the &lt;tt&gt;sys&lt;/tt&gt; module, &lt;tt&gt;setcheckinterval&lt;/tt&gt;, which 
you can call to tell the interpreter how often to perform these periodic
 checks. Prior to the release of Python 2.3 it defaulted to 10. In 2.3 
this was raised to 100. If you aren&#39;t running with threads and you don&#39;t
 expect to be catching many signals, setting this to a larger value can 
improve the interpreter&#39;s performance, sometimes substantially. &lt;span class=&quot;anchor&quot; id=&quot;line-730&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-731&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-732&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Python_is_not_C&quot;&gt;
Python is not C&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-733&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-734&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-735&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
It
 is also not Perl, Java, C++ or Haskell. Be careful when transferring 
your knowledge of how other languages perform to Python. A simple 
example serves to demonstrate:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-736&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-737&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-738&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-739&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-740&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-741&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-742&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-743&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-744&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-745&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-746&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-747&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-748&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-32&quot;&gt;&lt;/span&gt;% timeit.py -s &#39;x = 47&#39; &#39;x * 2&#39;
&lt;span class=&quot;anchor&quot; id=&quot;line-2-25&quot;&gt;&lt;/span&gt;loops, best of 3: 0.574 usec per loop
&lt;span class=&quot;anchor&quot; id=&quot;line-3-24&quot;&gt;&lt;/span&gt;% timeit.py -s &#39;x = 47&#39; &#39;x &amp;lt;&amp;lt; 1&#39;
&lt;span class=&quot;anchor&quot; id=&quot;line-4-21&quot;&gt;&lt;/span&gt;loops, best of 3: 0.524 usec per loop
&lt;span class=&quot;anchor&quot; id=&quot;line-5-19&quot;&gt;&lt;/span&gt;% timeit.py -s &#39;x = 47&#39; &#39;x + x&#39;
&lt;span class=&quot;anchor&quot; id=&quot;line-6-13&quot;&gt;&lt;/span&gt;loops, best of 3: 0.382 usec per loop&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-749&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-750&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-751&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Now consider the similar C programs (only the add version is shown):&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-752&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-753&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-754&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-755&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-756&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-757&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-758&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-759&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-760&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-761&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-762&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-763&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-764&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-765&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-766&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-767&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-768&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-769&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-33&quot;&gt;&lt;/span&gt;#include &amp;lt;stdio.h&amp;gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-2-26&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-3-25&quot;&gt;&lt;/span&gt;int main (int argc, char *argv[]) {
&lt;span class=&quot;anchor&quot; id=&quot;line-4-22&quot;&gt;&lt;/span&gt; int i = 47;
&lt;span class=&quot;anchor&quot; id=&quot;line-5-20&quot;&gt;&lt;/span&gt; int loop;
&lt;span class=&quot;anchor&quot; id=&quot;line-6-14&quot;&gt;&lt;/span&gt; for (loop=0; loop&amp;lt;500000000; loop++)
&lt;span class=&quot;anchor&quot; id=&quot;line-7-7&quot;&gt;&lt;/span&gt;  i + i;
&lt;span class=&quot;anchor&quot; id=&quot;line-8-5&quot;&gt;&lt;/span&gt; return 0;
&lt;span class=&quot;anchor&quot; id=&quot;line-9-5&quot;&gt;&lt;/span&gt;}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-770&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-771&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-772&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-773&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
and the execution times:&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-774&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-775&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-776&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-777&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-778&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-779&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-780&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-781&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-782&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-783&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-784&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-785&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-786&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-787&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-788&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-789&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-790&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-791&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-792&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-793&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-794&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-795&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-796&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-797&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-798&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-34&quot;&gt;&lt;/span&gt;% for prog in mult add shift ; do
&lt;span class=&quot;anchor&quot; id=&quot;line-2-27&quot;&gt;&lt;/span&gt;&amp;lt; for i in 1 2 3 ; do
&lt;span class=&quot;anchor&quot; id=&quot;line-3-26&quot;&gt;&lt;/span&gt;&amp;lt; echo -n &quot;$prog: &quot;
&lt;span class=&quot;anchor&quot; id=&quot;line-4-23&quot;&gt;&lt;/span&gt;&amp;lt; /usr/bin/time ./$prog
&lt;span class=&quot;anchor&quot; id=&quot;line-5-21&quot;&gt;&lt;/span&gt;&amp;lt; done
&lt;span class=&quot;anchor&quot; id=&quot;line-6-15&quot;&gt;&lt;/span&gt;&amp;lt; echo
&lt;span class=&quot;anchor&quot; id=&quot;line-7-8&quot;&gt;&lt;/span&gt;&amp;lt; done
&lt;span class=&quot;anchor&quot; id=&quot;line-8-6&quot;&gt;&lt;/span&gt;mult: 6.12 real 5.64 user 0.01 sys
&lt;span class=&quot;anchor&quot; id=&quot;line-9-6&quot;&gt;&lt;/span&gt;mult: 6.08 real 5.50 user 0.04 sys
&lt;span class=&quot;anchor&quot; id=&quot;line-10-5&quot;&gt;&lt;/span&gt;mult: 6.10 real 5.45 user 0.03 sys
&lt;span class=&quot;anchor&quot; id=&quot;line-11-4&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-12-3&quot;&gt;&lt;/span&gt;add: 6.07 real 5.54 user 0.00 sys
&lt;span class=&quot;anchor&quot; id=&quot;line-13-1&quot;&gt;&lt;/span&gt;add: 6.08 real 5.60 user 0.00 sys
&lt;span class=&quot;anchor&quot; id=&quot;line-14-1&quot;&gt;&lt;/span&gt;add: 6.07 real 5.58 user 0.01 sys
&lt;span class=&quot;anchor&quot; id=&quot;line-15-1&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-16&quot;&gt;&lt;/span&gt;shift: 6.09 real 5.55 user 0.01 sys
&lt;span class=&quot;anchor&quot; id=&quot;line-17&quot;&gt;&lt;/span&gt;shift: 6.10 real 5.62 user 0.01 sys
&lt;span class=&quot;anchor&quot; id=&quot;line-18&quot;&gt;&lt;/span&gt;shift: 6.06 real 5.50 user 0.01 sys&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-799&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-800&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-801&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Note
 that there is a significant advantage in Python to adding a number to 
itself instead of multiplying it by two or shifting it left by one bit. 
In C on all modern computer architectures, each of the three arithmetic 
operations are translated into a single machine instruction which 
executes in one cycle, so it doesn&#39;t really matter which one you choose.
 &lt;span class=&quot;anchor&quot; id=&quot;line-802&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-803&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-804&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
A common &quot;test&quot; new Python programmers often perform is to translate the common Perl idiom &lt;span class=&quot;anchor&quot; id=&quot;line-805&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-806&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-807&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-808&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-809&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-810&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-811&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-812&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-813&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-814&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-35&quot;&gt;&lt;/span&gt;while (&amp;lt;&amp;gt;) {
&lt;span class=&quot;anchor&quot; id=&quot;line-2-28&quot;&gt;&lt;/span&gt;    print;
&lt;span class=&quot;anchor&quot; id=&quot;line-3-27&quot;&gt;&lt;/span&gt;}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-815&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-816&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-817&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
into Python code that looks something like &lt;span class=&quot;anchor&quot; id=&quot;line-818&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-819&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-820&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-821&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-822&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-823&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-824&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-825&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-826&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-827&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-828&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-829&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-830&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-36&quot;&gt;&lt;/span&gt;import fileinput
&lt;span class=&quot;anchor&quot; id=&quot;line-2-29&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-3-28&quot;&gt;&lt;/span&gt;for line in fileinput.input():
&lt;span class=&quot;anchor&quot; id=&quot;line-4-24&quot;&gt;&lt;/span&gt;    print line,&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-831&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-832&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-833&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-834&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
and
 use it to conclude that Python must be much slower than Perl. As others
 have pointed out numerous times, Python is slower than Perl for some 
things and faster for others. Relative performance also often depends on
 your experience with the two languages. &lt;span class=&quot;anchor&quot; id=&quot;line-835&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-836&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-837&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Use_xrange_instead_of_range&quot;&gt;
Use xrange instead of range&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-838&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-839&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-840&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-841&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-842&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-843&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-844&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
This section no longer applies if you&#39;re using Python 3, where &lt;tt class=&quot;backtick&quot;&gt;range&lt;/tt&gt; now provides an iterator over ranges of arbitrary size, and where &lt;tt class=&quot;backtick&quot;&gt;xrange&lt;/tt&gt; no longer exists. &lt;span class=&quot;anchor&quot; id=&quot;line-845&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-846&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-847&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-848&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-849&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
Python has two ways to get a range of numbers: &lt;tt&gt;range&lt;/tt&gt; and &lt;tt&gt;xrange&lt;/tt&gt;. Most people know about &lt;tt&gt;range&lt;/tt&gt;, because of its obvious name. &lt;tt&gt;xrange&lt;/tt&gt;, being way down near the end of the alphabet, is much less well-known. &lt;span class=&quot;anchor&quot; id=&quot;line-850&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-851&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-852&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;tt&gt;xrange&lt;/tt&gt; is a generator object, basically equivalent to the following Python 2.3 code: &lt;span class=&quot;anchor&quot; id=&quot;line-853&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-854&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-855&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-856&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-857&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-858&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-859&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-860&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-861&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-862&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-863&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-864&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-865&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-866&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-867&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-868&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-869&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-870&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-871&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-872&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-873&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-37&quot;&gt;&lt;/span&gt;def xrange(start, stop=None, step=1):
&lt;span class=&quot;anchor&quot; id=&quot;line-2-30&quot;&gt;&lt;/span&gt;    if stop is None:
&lt;span class=&quot;anchor&quot; id=&quot;line-3-29&quot;&gt;&lt;/span&gt;        stop = start
&lt;span class=&quot;anchor&quot; id=&quot;line-4-25&quot;&gt;&lt;/span&gt;        start = 0
&lt;span class=&quot;anchor&quot; id=&quot;line-5-22&quot;&gt;&lt;/span&gt;    else:
&lt;span class=&quot;anchor&quot; id=&quot;line-6-16&quot;&gt;&lt;/span&gt;        stop = int(stop)
&lt;span class=&quot;anchor&quot; id=&quot;line-7-9&quot;&gt;&lt;/span&gt;    start = int(start)
&lt;span class=&quot;anchor&quot; id=&quot;line-8-7&quot;&gt;&lt;/span&gt;    step = int(step)
&lt;span class=&quot;anchor&quot; id=&quot;line-9-7&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-10-6&quot;&gt;&lt;/span&gt;    while start &amp;lt; stop:
&lt;span class=&quot;anchor&quot; id=&quot;line-11-5&quot;&gt;&lt;/span&gt;        yield start
&lt;span class=&quot;anchor&quot; id=&quot;line-12-4&quot;&gt;&lt;/span&gt;        start += step&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-874&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-875&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-876&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-877&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Except that it is implemented in pure C.&lt;span class=&quot;anchor&quot; id=&quot;line-878&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-879&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-880&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;tt&gt;xrange&lt;/tt&gt; does have limitations. Specifically, it only works with &lt;tt&gt;int&lt;/tt&gt;s; you cannot use &lt;tt&gt;long&lt;/tt&gt;s or &lt;tt&gt;float&lt;/tt&gt;s (they will be converted to &lt;tt&gt;int&lt;/tt&gt;s, as shown above). &lt;span class=&quot;anchor&quot; id=&quot;line-881&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-882&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-883&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
It
 does, however, save gobs of memory, and unless you store the yielded 
objects somewhere, only one yielded object will exist at a time. The 
difference is thus: When you call &lt;tt&gt;range&lt;/tt&gt;, it creates a &lt;tt&gt;list&lt;/tt&gt; containing so many number (&lt;tt&gt;int&lt;/tt&gt;, &lt;tt&gt;long&lt;/tt&gt;, or &lt;tt&gt;float&lt;/tt&gt;)
 objects. All of those objects are created at once, and all of them 
exist at the same time. This can be a pain when the number of numbers is
 large. &lt;span class=&quot;anchor&quot; id=&quot;line-884&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-885&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-886&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;tt&gt;xrange&lt;/tt&gt;, on the other hand, creates &lt;i&gt;no&lt;/i&gt;
 numbers immediately - only the range object itself. Number objects are 
created only when you pull on the generator, e.g. by looping through it.
 For example: &lt;span class=&quot;anchor&quot; id=&quot;line-887&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-888&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-889&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-890&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-891&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-892&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-893&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-894&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-895&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-896&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-38&quot;&gt;&lt;/span&gt;xrange(sys.maxint) # No loop, and no call to .next, so no numbers are instantiated&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-897&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-898&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-899&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-900&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
And for this reason, the code runs instantly. If you substitute &lt;tt&gt;range&lt;/tt&gt; there, Python will lock up; it will be too busy allocating &lt;tt&gt;sys.maxint&lt;/tt&gt; number objects (about 2.1 billion on the typical PC) to do anything else. Eventually, it will run out of memory and exit. &lt;span class=&quot;anchor&quot; id=&quot;line-901&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-902&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-903&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
In Python versions before 2.2, &lt;tt&gt;xrange&lt;/tt&gt; objects also supported optimizations such as fast membership testing (&lt;tt&gt;i&amp;nbsp;in&amp;nbsp;xrange(n)&lt;/tt&gt;). These features were removed in 2.2 due to lack of use. &lt;span class=&quot;anchor&quot; id=&quot;line-904&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-905&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-906&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Re-map_Functions_at_runtime&quot;&gt;
Re-map Functions at runtime&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-907&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-908&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-909&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Say you have a function &lt;span class=&quot;anchor&quot; id=&quot;line-910&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-911&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-912&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-913&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-914&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-915&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-916&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-917&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-918&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-919&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-920&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-921&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-922&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-923&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-924&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-925&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-926&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-927&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-928&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-929&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-930&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-931&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-932&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-39&quot;&gt;&lt;/span&gt; class Test:
&lt;span class=&quot;anchor&quot; id=&quot;line-2-31&quot;&gt;&lt;/span&gt;   def check(self,a,b,c):
&lt;span class=&quot;anchor&quot; id=&quot;line-3-30&quot;&gt;&lt;/span&gt;     if a == 0:
&lt;span class=&quot;anchor&quot; id=&quot;line-4-26&quot;&gt;&lt;/span&gt;       self.str = b*100
&lt;span class=&quot;anchor&quot; id=&quot;line-5-23&quot;&gt;&lt;/span&gt;     else:
&lt;span class=&quot;anchor&quot; id=&quot;line-6-17&quot;&gt;&lt;/span&gt;       self.str = c*100
&lt;span class=&quot;anchor&quot; id=&quot;line-7-10&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-8-8&quot;&gt;&lt;/span&gt; a = Test()
&lt;span class=&quot;anchor&quot; id=&quot;line-9-8&quot;&gt;&lt;/span&gt; def example():
&lt;span class=&quot;anchor&quot; id=&quot;line-10-7&quot;&gt;&lt;/span&gt;   for i in xrange(0,100000):
&lt;span class=&quot;anchor&quot; id=&quot;line-11-6&quot;&gt;&lt;/span&gt;     a.check(i,&quot;b&quot;,&quot;c&quot;)
&lt;span class=&quot;anchor&quot; id=&quot;line-12-5&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-13-2&quot;&gt;&lt;/span&gt; import profile
&lt;span class=&quot;anchor&quot; id=&quot;line-14-2&quot;&gt;&lt;/span&gt; profile.run(&quot;example()&quot;)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-933&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-934&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-935&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-936&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
And suppose this function gets called from somewhere else many times. &lt;span class=&quot;anchor&quot; id=&quot;line-937&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-938&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-939&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Well, your check will have an if statement slowing you down all the time except the first time, so you can do this: &lt;span class=&quot;anchor&quot; id=&quot;line-940&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-941&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-942&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-943&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-944&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-945&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-946&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-947&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-948&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-949&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-950&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-951&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-952&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-953&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-954&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-955&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-956&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-957&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-958&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-959&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-960&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-961&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-962&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-40&quot;&gt;&lt;/span&gt; class Test2:
&lt;span class=&quot;anchor&quot; id=&quot;line-2-32&quot;&gt;&lt;/span&gt;   def check(self,a,b,c):
&lt;span class=&quot;anchor&quot; id=&quot;line-3-31&quot;&gt;&lt;/span&gt;     self.str = b*100
&lt;span class=&quot;anchor&quot; id=&quot;line-4-27&quot;&gt;&lt;/span&gt;     self.check = self.check_post
&lt;span class=&quot;anchor&quot; id=&quot;line-5-24&quot;&gt;&lt;/span&gt;   def check_post(self,a,b,c):
&lt;span class=&quot;anchor&quot; id=&quot;line-6-18&quot;&gt;&lt;/span&gt;     self.str = c*100
&lt;span class=&quot;anchor&quot; id=&quot;line-7-11&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-8-9&quot;&gt;&lt;/span&gt; a = Test2()
&lt;span class=&quot;anchor&quot; id=&quot;line-9-9&quot;&gt;&lt;/span&gt; def example2():
&lt;span class=&quot;anchor&quot; id=&quot;line-10-8&quot;&gt;&lt;/span&gt;   for i in xrange(0,100000):
&lt;span class=&quot;anchor&quot; id=&quot;line-11-7&quot;&gt;&lt;/span&gt;     a.check(i,&quot;b&quot;,&quot;c&quot;)
&lt;span class=&quot;anchor&quot; id=&quot;line-12-6&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-13-3&quot;&gt;&lt;/span&gt; import profile
&lt;span class=&quot;anchor&quot; id=&quot;line-14-3&quot;&gt;&lt;/span&gt; profile.run(&quot;example2()&quot;)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-963&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-964&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-965&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-966&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line874&quot;&gt;
Well,
 this example is fairly inadequate, but if the &#39;if&#39; statement is a 
pretty complicated expression (or something with lots of dots), you can 
save yourself evaluating it, if you know it will only be true the first 
time. &lt;span class=&quot;anchor&quot; id=&quot;line-967&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-968&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-969&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-970&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-971&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-972&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Profiling_Code&quot;&gt;
Profiling Code&lt;/h2&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-973&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-974&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-975&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
The
 first step to speeding up your program is learning where the 
bottlenecks lie. It hardly makes sense to optimize code that is never 
executed or that already runs fast. I use two modules to help locate the
 hotspots in my code, profile and trace. In later examples I also use 
the &lt;tt&gt;timeit&lt;/tt&gt; module, which is new in Python 2.3. &lt;span class=&quot;anchor&quot; id=&quot;line-976&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-977&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-978&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;img alt=&quot;(!)&quot; height=&quot;16&quot; src=&quot;https://wiki.python.org/wiki/europython/img/idea.png&quot; title=&quot;(!)&quot; width=&quot;16&quot; /&gt; See the separate &lt;a href=&quot;https://wiki.python.org/moin/PythonSpeed/Profiling&quot;&gt;profiling&lt;/a&gt; document for alternatives to the approaches given below. &lt;span class=&quot;anchor&quot; id=&quot;line-979&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-980&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-981&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h3 id=&quot;Profiling&quot;&gt;
Profiling&lt;/h3&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-982&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-983&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-984&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
There are a number of &lt;a class=&quot;http&quot; href=&quot;http://docs.python.org/library/profile.html&quot;&gt;profiling modules&lt;/a&gt;
 included in the Python distribution. Using one of these to profile the 
execution of a set of functions is quite easy. Suppose your main 
function is called &lt;tt class=&quot;backtick&quot;&gt;main&lt;/tt&gt;, takes no arguments and you want to execute it under the control of the &lt;tt class=&quot;backtick&quot;&gt;profile&lt;/tt&gt; module. In its simplest form you just execute&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-985&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-986&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-987&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-988&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-989&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-990&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-991&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-992&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-993&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-994&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-995&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-41&quot;&gt;&lt;/span&gt;import profile
&lt;span class=&quot;anchor&quot; id=&quot;line-2-33&quot;&gt;&lt;/span&gt;profile.run(&#39;main()&#39;)&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-996&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-997&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-998&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-999&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
When &lt;tt class=&quot;backtick&quot;&gt;main()&lt;/tt&gt; returns, the &lt;tt class=&quot;backtick&quot;&gt;profile&lt;/tt&gt; module will print a table of function calls and execution times. The output can be tweaked using the &lt;tt class=&quot;backtick&quot;&gt;Stats&lt;/tt&gt; class included with the module. From Python 2.4 &lt;tt class=&quot;backtick&quot;&gt;profile&lt;/tt&gt; has permitted the time consumed by Python builtins and functions in extension modules to be profiled as well. &lt;span class=&quot;anchor&quot; id=&quot;line-1000&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1001&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1002&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
A slightly longer description of profiling using the &lt;tt class=&quot;backtick&quot;&gt;profile&lt;/tt&gt; and &lt;tt class=&quot;backtick&quot;&gt;pstats&lt;/tt&gt; modules can be found here (archived version):&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line862&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1003&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1004&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1005&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;a class=&quot;http&quot; href=&quot;http://web.archive.org/web/20060506162444/http://wingware.com/doc/howtos/performance-profiling-python-code&quot;&gt;http://web.archive.org/web/20060506162444/http://wingware.com/doc/howtos/performance-profiling-python-code&lt;/a&gt; &lt;span class=&quot;anchor&quot; id=&quot;line-1006&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1007&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1008&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h3 id=&quot;The_cProfile_and_Hotshot_Modules&quot;&gt;
The cProfile and Hotshot Modules&lt;/h3&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1009&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1010&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1011&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
Since Python 2.2, the &lt;a class=&quot;http&quot; href=&quot;http://www.python.org/doc/current/lib/module-hotshot.html&quot;&gt;hotshot package&lt;/a&gt; has been available as a replacement for the &lt;tt class=&quot;backtick&quot;&gt;profile&lt;/tt&gt; module, although the &lt;tt class=&quot;backtick&quot;&gt;cProfile&lt;/tt&gt; module is now recommended in preference to &lt;tt class=&quot;backtick&quot;&gt;hotshot&lt;/tt&gt;. The underlying module is written in C, so using &lt;tt class=&quot;backtick&quot;&gt;hotshot&lt;/tt&gt; (or &lt;tt class=&quot;backtick&quot;&gt;cProfile&lt;/tt&gt;)
 should result in a much smaller performance hit, and thus a more 
accurate idea of how your application is performing. There is also a &lt;tt class=&quot;backtick&quot;&gt;hotshotmain.py&lt;/tt&gt; program in the distribution&#39;s &lt;tt class=&quot;backtick&quot;&gt;Tools/scripts&lt;/tt&gt; directory which makes it easy to run your program under &lt;tt class=&quot;backtick&quot;&gt;hotshot&lt;/tt&gt; control from the command line. &lt;span class=&quot;anchor&quot; id=&quot;line-1012&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1013&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1014&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h3 id=&quot;Trace_Module&quot;&gt;
Trace Module&lt;/h3&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1015&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1016&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1017&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
The &lt;a class=&quot;http&quot; href=&quot;http://www.python.org/doc/current/lib/module-trace.html&quot;&gt;trace module&lt;/a&gt;
 is a spin-off of the profile module as of 
Python 2.0 you should find trace.py in the Tools/scripts directory of 
the Python distribution. Starting with Python 2.3 it&#39;s in the standard 
library (the Lib directory). You can copy it to your local bin directory
 and set the execute permission, then execute it directly. It&#39;s easy to 
run from the command line to trace execution of whole scripts: &lt;span class=&quot;anchor&quot; id=&quot;line-1018&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1019&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1020&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1021&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1022&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1023&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1024&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1025&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-42&quot;&gt;&lt;/span&gt;% trace.py -t spam.py eggs&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1026&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1027&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1028&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line862&quot;&gt;
In Python 2.4 it&#39;s even easier to run. Just execute &lt;tt&gt;python&amp;nbsp;-m&amp;nbsp;trace&lt;/tt&gt;. &lt;span class=&quot;anchor&quot; id=&quot;line-1029&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1030&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1031&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
There&#39;s no separate documentation, but you can execute &quot;pydoc trace&quot; to view the inline documentation. &lt;span class=&quot;anchor&quot; id=&quot;line-1032&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1033&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1034&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;/div&gt;
&lt;h3 id=&quot;Visualizing_Profiling_Results&quot;&gt;
Visualizing Profiling Results&lt;/h3&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1035&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1036&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1037&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;a class=&quot;http&quot; href=&quot;http://www.vrplumber.com/programming/runsnakerun/&quot;&gt;RunSnakeRun&lt;/a&gt;
 is a GUI tool by Mike Fletcher which visualizes profile dumps from 
cProfile using square maps. Function/method calls may be sorted 
according to various criteria, and source code may be displayed 
alongside the visualization and call statistics. &lt;span class=&quot;anchor&quot; id=&quot;line-1038&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1039&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1040&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
An example usage: &lt;span class=&quot;anchor&quot; id=&quot;line-1041&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1042&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1043&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1044&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1045&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-43&quot;&gt;&lt;/span&gt;runsnake some_profile_dump.prof&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1046&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1047&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1048&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;a class=&quot;http&quot; href=&quot;http://code.google.com/p/jrfonseca/wiki/Gprof2Dot&quot;&gt;Gprof2Dot&lt;/a&gt; is a python based tool that can transform profiling results output into a graph that can be converted into a PNG image or SVG. &lt;span class=&quot;anchor&quot; id=&quot;line-1049&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1050&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1051&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
A
 typical profiling session with python 2.5 looks like this (on older 
platforms you will need to use actual script instead of the -m option):&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1052&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1053&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1054&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1055&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1056&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1057&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1058&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-44&quot;&gt;&lt;/span&gt;python -m cProfile -o stat.prof MYSCRIPY.PY [ARGS...]
&lt;span class=&quot;anchor&quot; id=&quot;line-2-34&quot;&gt;&lt;/span&gt;python -m pbp.scripts.gprof2dot -f pstats -o stat.dot stat.prof
&lt;span class=&quot;anchor&quot; id=&quot;line-3-32&quot;&gt;&lt;/span&gt;dot -ostat.png -Tpng stat.dot&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1059&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1060&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1061&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;a class=&quot;http&quot; href=&quot;http://pycallgraph.slowchop.com/&quot;&gt;PyCallGraph&lt;/a&gt;
 pycallgraph is a Python module that creates call graphs for Python 
programs. It generates a PNG file showing an modules&#39;s function calls 
and their link to other function calls, the amount of times a function 
was called and the time spent in that function. &lt;span class=&quot;anchor&quot; id=&quot;line-1062&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1063&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1064&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Typical usage: &lt;span class=&quot;anchor&quot; id=&quot;line-1065&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1066&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1067&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1068&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1069&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-45&quot;&gt;&lt;/span&gt;pycallgraph scriptname.py&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1070&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1071&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1072&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;a class=&quot;https&quot; href=&quot;https://bitbucket.org/ogrisel/pyprof2calltree&quot;&gt;PyProf2CallTree&lt;/a&gt; is a script to help visualize profiling data collected with the cProfile python module with the &lt;a class=&quot;http&quot; href=&quot;http://kcachegrind.sourceforge.net/html/Home.html&quot;&gt;kcachegrind&lt;/a&gt; graphical calltree analyser. &lt;span class=&quot;anchor&quot; id=&quot;line-1073&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1074&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1075&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
Typical usage:&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;line874&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1076&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1077&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1078&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line867&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;line-1079&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1080&quot;&gt;&lt;/span&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1081&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;anchor&quot; id=&quot;line-1-46&quot;&gt;&lt;/span&gt;python -m cProfile -o stat.prof MYSCRIPY.PY [ARGS...]
&lt;span class=&quot;anchor&quot; id=&quot;line-2-35&quot;&gt;&lt;/span&gt;python pyprof2calltree.py -i stat.prof -k&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;br /&gt;
Good luck have fun! </content><link rel='replies' type='application/atom+xml' href='http://xyzmind.blogspot.com/feeds/2586069122282404980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xyzmind.blogspot.com/2015/01/python-performance-tips.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/2586069122282404980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3524535260938031835/posts/default/2586069122282404980'/><link rel='alternate' type='text/html' href='http://xyzmind.blogspot.com/2015/01/python-performance-tips.html' title='Python Performance Tips'/><author><name>Amru Rosyada</name><uri>http://www.blogger.com/profile/08446630123821457752</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry></feed>