{"id":29839,"date":"2023-02-26T13:40:44","date_gmt":"2023-02-26T13:40:44","guid":{"rendered":"https:\/\/holypython.com\/?p=29839"},"modified":"2023-02-26T14:45:22","modified_gmt":"2023-02-26T14:45:22","slug":"advanced-level-python-tips-tricks","status":"publish","type":"post","link":"https:\/\/holypython.com\/advanced-level-python-tips-tricks\/","title":{"rendered":"Advanced Level Python Tips &#038; Tricks"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"29839\" class=\"elementor elementor-29839\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-522baf2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"522baf2\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-22c9673\" data-id=\"22c9673\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c892b23 elementor-widget elementor-widget-menu-anchor\" data-id=\"c892b23\" data-element_type=\"widget\" data-widget_type=\"menu-anchor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-menu-anchor\" id=\"adv\"><\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-8d13315 elementor-section-content-middle elementor-section-height-min-height elementor-section-boxed elementor-section-height-default\" data-id=\"8d13315\" data-element_type=\"section\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-a071d29\" data-id=\"a071d29\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-eafe2ef elementor-widget elementor-widget-heading\" data-id=\"eafe2ef\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Python Tips &amp; Tricks (Part III)<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9a619c9 elementor-widget elementor-widget-heading\" data-id=\"9a619c9\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Advanced Level<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-28c5356 elementor-widget elementor-widget-heading\" data-id=\"28c5356\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">HolyPython.com<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-da20e15 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"da20e15\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-5ffed34\" data-id=\"5ffed34\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-18642c7 elementor-widget elementor-widget-text-editor\" data-id=\"18642c7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p class=\"language-python\">Here are more Python tips about relatively more complex Python concepts.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-55388dc elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"55388dc\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">71) Annotated Assignment Statement: (<i>:<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7a5c0ba elementor-widget elementor-widget-text-editor\" data-id=\"7a5c0ba\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This might not seem as impressive as some other tricks but it&#8217;s a new syntax that was introduced to Python in recent years and just good to be aware of.<\/p><p>Annotated assignments allow the coder to leave <strong>type hints\u00a0<\/strong>in the code. These don&#8217;t have any enforcing power at least not yet. It&#8217;s still nice to be able to imply some type hints and definitely offers more options than only being able to comment regarding expected types of variables.<\/p><p>Check out some of these examples:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-423b4dc elementor-widget elementor-widget-html\" data-id=\"423b4dc\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>day: str = 'Saturday'\nprint(day)\n\nlst: list = [1,2,3]\nprint(lst)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f86d453 elementor-widget elementor-widget-text-editor\" data-id=\"f86d453\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>'Saturday'<br \/>[1,2,3]<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a3c180a elementor-widget elementor-widget-text-editor\" data-id=\"a3c180a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The slightly less cool and older implementation would be like this:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-49813f5 elementor-widget elementor-widget-html\" data-id=\"49813f5\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>day= 'Saturday' #str\nprint(day)\n\nlst= [1,2,3] # list\nprint(lst)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ff0b2f3 elementor-widget elementor-widget-text-editor\" data-id=\"ff0b2f3\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can read Python Official Documentation about Annotated Assignments <a href=\"https:\/\/docs.python.org\/3\/reference\/simple_stmts.html\">here<\/a>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0ca05ea elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"0ca05ea\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">72) Yield Statement: (<i><\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-57564b0 elementor-widget elementor-widget-text-editor\" data-id=\"57564b0\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can think of yield statement in the same category as the <strong>return<\/strong> statement. The difference is, while return statement returns a value and the function ends, yield statement can return a sequence of values, it sort of yields, hence the name.<\/p><p>If you&#8217;re interested in algorithms, here is a nice demonstration of <a href=\"https:\/\/holypython.com\/bubble-sort-algorithm-python-code\/\">Bubble Sort Algorithm Visualization<\/a> where you can see how yield is needed and used.<\/p><p>Also, here are a couple of examples with yield statement:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c499c9b elementor-widget elementor-widget-html\" data-id=\"c499c9b\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>def f1(a):\n    yield a\n    yield a**2\n    yield a**3\n    \nprint (f1(5))\n\nfor i in f1(5):\n    print (i)    \n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e22bac9 elementor-widget elementor-widget-text-editor\" data-id=\"e22bac9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>&lt;generator object f1 at 0x00000275EF339AC8&gt;\n5\n25\n125<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4b078c3 elementor-widget elementor-widget-html\" data-id=\"4b078c3\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>def f2(b):\n    for j in range(b):\n        yield j\n\nfor i in f2(5):\n    print(i)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3372988 elementor-widget elementor-widget-text-editor\" data-id=\"3372988\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>0<br \/>1<br \/>2<br \/>3<br \/>4<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b44d9ee elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"b44d9ee\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">73) News brought to you by: (<i>Python Newspaper<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c73841e elementor-widget elementor-widget-text-editor\" data-id=\"c73841e\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Another fabulous Python library newspaper3k gives a whole another meaning to newspaper access.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9b71136 elementor-widget elementor-widget-image\" data-id=\"9b71136\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"684\" height=\"453\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/995cb1ef9efa-Custom-1.jpg\" class=\"attachment-large size-large wp-image-10951\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/995cb1ef9efa-Custom-1.jpg 684w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/995cb1ef9efa-Custom-1-300x199.jpg 300w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Sleek businessperson reading business newspaper<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cc32505 elementor-widget elementor-widget-text-editor\" data-id=\"cc32505\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can install newspaper3k via pip from your Anaconda Command Prompt. If you need more instructions you can check out this article regarding <a href=\"https:\/\/holypython.com\/installing-pip-packages-with-anaconda\/\">how to install packages using pip with Anaconda<\/a>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fb3dbd9 elementor-widget elementor-widget-html\" data-id=\"fb3dbd9\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>pip install newspaper\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ffa901a elementor-widget elementor-widget-text-editor\" data-id=\"ffa901a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>After installing newspaper3k you can start using it. Here are some examples:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3229fc4 elementor-widget elementor-widget-html\" data-id=\"3229fc4\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import newspaper\n\npaper = newspaper.build('http:\/\/theatlantic.com')\n\nfor article in paper.articles:\n    print(article.url)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-185e262 elementor-widget elementor-widget-text-editor\" data-id=\"185e262\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Code above will list all the articles found in the entire newspaper.<\/p><p>Check out the code below to see all the other attributes you can conveniently extract from a single article or a whole newspaper.<\/p><p>Information is power, when managed well it can offer great contributions to specific tasks, projects and objectives.<\/p><p>\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ce7960b elementor-widget elementor-widget-html\" data-id=\"ce7960b\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from newspaper import Article\n\nurl = 'https:\/\/www.theatlantic.com\/ideas\/archive\/2020\/06\/daca-activism\/613213\/'\narticle = Article(url)\n\narticle.download()\narticle.parse()\n\n\nprint(article.text)\nprint(article.authors)\nprint(article.publish_date)\nprint(article.images)\nprint(article.title)\nprint(article.tags)\nprint(article.summary)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cae37e7 elementor-widget elementor-widget-text-editor\" data-id=\"cae37e7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can see the Github repository of this cool Python library here: <a href=\"https:\/\/github.com\/codelucas\/newspaper\/\">Newspaper 3k Github<\/a><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1dee735 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"1dee735\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">74) Geopy: (<i>Work on Open File<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-91efb7a elementor-widget elementor-widget-text-editor\" data-id=\"91efb7a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Geopy is another great library that can be used for geocoding services. Converting open addresses to longitude and latitude values or converting coordinates to addresses is called geocoding. It&#8217;s a common application with almost any location related service such as media sharing, social network, navigation, transportation, streaming, gaming, websites, communication, identification, security etc.<\/p><p>Here are some simple examples to demonstrate what you can quickly do with geopy library using the address of New York rooftop bar <strong>230 Fifth.<\/strong><\/p><p>Please note that you might need to change the user_agent to avoid application errors. One common error related to user_agent is InsufficientPrivilege Error.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2428b2a elementor-widget elementor-widget-html\" data-id=\"2428b2a\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from geopy.geocoders import Nominatim\ngeolocator = Nominatim(user_agent=\"HiApp\")\nlocation = geolocator.geocode(\" 230 Fifth Ave, New York\")\n\nprint(location.address)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-44ea9c2 elementor-widget elementor-widget-text-editor\" data-id=\"44ea9c2\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>230, Fifth Avenue, Sheridan Meadows, Amherst Town, Erie County, New York, 14221, United States of America<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-534a341 elementor-widget elementor-widget-html\" data-id=\"534a341\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>print((location.latitude, location.longitude))\n\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1b63e2c elementor-widget elementor-widget-text-editor\" data-id=\"1b63e2c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>(42.983481438214326, -78.70683044449504)<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ccd08a4 elementor-widget elementor-widget-html\" data-id=\"ccd08a4\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>print(location.raw)\n\n\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4f5199b elementor-widget elementor-widget-text-editor\" data-id=\"4f5199b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>{'place_id': 259174015, 'licence': 'Data \u00a9 OpenStreetMap contributors, ODbL 1.0. \nhttps:\/\/osm.org\/copyright', 'osm_type': 'way', 'osm_id': 12316939, 'boundingbox': \n['42.983431438214', '42.983531438214', '-78.706880444495', '-78.706780444495'], \n'lat': '42.983481438214326', 'lon': '-78.70683044449504', 'display_name': '230, \nFifth Avenue, Sheridan Meadows, Amherst Town, Erie County, New York, 14221, \nUnited States of America', 'class': 'place', 'type': 'house', 'importance': 0.511}<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-dbf5cab elementor-widget elementor-widget-text-editor\" data-id=\"dbf5cab\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Open Street Map&#8217;s Nominatim is a very convenient geocoding service but you should check their official documentation for any serious use case.<\/p><p>Some other similar web services are\u00a0Geonames, Yandex Map API,\u00a0Bing Map API, Google Maps API V3 and Yahoo BOSS Finder. They all offer different usage benefits.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-67a3001 elementor-widget elementor-widget-image\" data-id=\"67a3001\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"769\" height=\"538\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/0c1d3a81b06-Custom.png\" class=\"attachment-full size-full wp-image-10947\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/0c1d3a81b06-Custom.png 769w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/0c1d3a81b06-Custom-300x210.png 300w\" sizes=\"(max-width: 769px) 100vw, 769px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Big Apple and Lake States Satellite View at Night<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3260853 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"3260853\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">75) sh: (<i>Shell scripts and bash commands<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1830ad2 elementor-widget elementor-widget-text-editor\" data-id=\"1830ad2\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>sh is a subprocess wrapper that can be used to dynamically map system functions to Python. It facilitates writing shell scripts with bash features.<\/p><p>Unfortunately latest version of sh only works for linux and Mac. If you&#8217;re using Windows you&#8217;ll need to install an old version that can be found <a href=\"https:\/\/pypi.org\/project\/pbs\/\">here<\/a>.<\/p><p>Let&#8217;s check out some examples of what can be done with sh:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-faffb4e elementor-widget elementor-widget-html\" data-id=\"faffb4e\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import sh\r\nsh.google_chrome(\"http:\/\/google.com\u201d)\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-532fa79 elementor-widget elementor-widget-text-editor\" data-id=\"532fa79\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here are some other ideas:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2b7f835 elementor-widget elementor-widget-html\" data-id=\"2b7f835\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import sh\r\n\r\nsh.whoami()\r\nsh.pwd()\r\nsh.mkdir('foldername')\r\nsh.touch('filename.txt')\r\nsh.echo('Hello World')\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-42d0fe2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"42d0fe2\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-8b02ae4\" data-id=\"8b02ae4\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-62310c8 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"62310c8\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">76) Decorators: (<i>Augmenting functions without modifications<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-72460d2 elementor-widget elementor-widget-text-editor\" data-id=\"72460d2\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Decorators are another elegant representative of Python&#8217;s expressive and minimalistic syntax.<\/p><p>By using decorators you can change a function&#8217;s behavior or outcome without actually modifying it.<\/p><p>In other words decorators decorate functions to make them fancier in some way.<\/p><p>A decorator starts with <strong>@ <\/strong>sign in Python syntax and is placed just before the function.<\/p><p>Here are some simple examples:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cdf894f elementor-widget elementor-widget-text-editor\" data-id=\"cdf894f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Let&#8217;s say we have a simple function that adds 2 numbers.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ee320e7 elementor-widget elementor-widget-html\" data-id=\"ee320e7\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>def adder(a, b): \r\n    return a+b\r\n    \r\nprint(adder(2, 3))\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9d049a0 elementor-widget elementor-widget-text-editor\" data-id=\"9d049a0\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>5<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6cf99de elementor-widget elementor-widget-text-editor\" data-id=\"6cf99de\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Now, without touching the original function, let&#8217;s decorate it so that it multiplies the result by 100.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c492d54 elementor-widget elementor-widget-html\" data-id=\"c492d54\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>def decoten(func): \r\n    def times10(x, y): \r\n        return func(x*10, y*10) \r\n    return times10\r\n\r\n@decoten\r\ndef adder(a, b): \r\n    return a+b \r\n\r\nprint(adder(2,3))\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-48c5dfd elementor-widget elementor-widget-text-editor\" data-id=\"48c5dfd\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>50<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a0f32fb elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"a0f32fb\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">77: Memory Optimization: (<i>__slots__<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2b72f26 elementor-widget elementor-widget-text-editor\" data-id=\"2b72f26\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>At the advanced level Python can have<\/p><p>When you start editing default Python implementations for speed and efficiency reasons you know you&#8217;re starting to get into the expert territory.<\/p><p>Python classes utilize dictionaries for instant attributes by default which can take quite a space even when you&#8217;re constructing a class object.<\/p><p>When this is the case you can use __slots__ magic to force Python not to have a big chunks default instance attribute dictionary and instead have a small custom list. This can save lots of memory in suitable applications.<\/p><p>On top of that, another benefit of __slots__ is faster access to class attributes.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6dd08e9 elementor-widget elementor-widget-text-editor\" data-id=\"6dd08e9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>Real Madrid : 5<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-443d7c5 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"443d7c5\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-1be8abd\" data-id=\"1be8abd\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e4a7e15 elementor-widget elementor-widget-html\" data-id=\"e4a7e15\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>class Team:\r\n    __slots__ = [\"name\", \"score\"]\r\n    def __init__(self, name, score):\r\n        self.name = name\r\n        self.score = score\r\n        \r\n\r\na=Team(\"Real Madrid\", 5)\r\nprint(a.name, a.score, sep=\" : \")\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f051807 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"f051807\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">78) Time it: (<i>Time Processes<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5fdc7ea elementor-widget elementor-widget-text-editor\" data-id=\"5fdc7ea\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>timeit library is great for timing Python execution times. Just pass a function in string format to <b>timeit.timeit()<\/b> method and it will carry out 1 million executions to report the minimum time the code takes.<\/p><p>Its very useful to compare small code pieces and different functions but can be sluggish with big code.<\/p><p>Check out the example below demonstrating the execution time difference between 2 very similar list comprehension methods in Python:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-796d6fb elementor-widget elementor-widget-html\" data-id=\"796d6fb\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import timeit\r\n\r\nlst1='''list(range(1000))'''\r\nlst2='''[i for i in range(1000)]'''\r\n\r\nx=timeit.timeit(lst1)\r\ny=timeit.timeit(lst2)\r\n\r\nprint(x, y, sep=\"------\")<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d3e8c73 elementor-widget elementor-widget-text-editor\" data-id=\"d3e8c73\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>11.646945999999843 ------- 27.643676500000083<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3cd83c3 elementor-widget elementor-widget-text-editor\" data-id=\"3cd83c3\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>timeit library is great for timing Python execution times. Just pass a function in string format to timeit.timeit() method and it will carry out 1 million executions to report the minimum time the code takes.<\/p>\n<p>Its very useful to compare small code pieces and different functions but can be sluggish with big code.<\/p><p>Check out the example below demonstrating the execution time difference between 2 very similar list comprehension methods in Python:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-412b817 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"412b817\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">79) Virtual env: (<i>Managing Dependencies<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6895904 elementor-widget elementor-widget-text-editor\" data-id=\"6895904\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Virtual Environment lets programmer create a specific environment with different versions of libraries when needed.<\/p><p>When the developer needs only certain versions of modules and libraries because development requires it virtual environment can be a practical solution.<\/p><p>It&#8217;s also quite straightforward with Python.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-df8c2c1 elementor-widget elementor-widget-text-editor\" data-id=\"df8c2c1\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Make sure virtualenv module is installed (Installed by default in Anaconda3)<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9054139 elementor-widget elementor-widget-html\" data-id=\"9054139\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>pip install virtualenv<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c47ca1a elementor-widget elementor-widget-text-editor\" data-id=\"c47ca1a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>To create a virtual environment type virtualenv followed by an environment name you&#8217;d like:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-eb251f1 elementor-widget elementor-widget-html\" data-id=\"eb251f1\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>virtualenv environment1<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5ac1c6a elementor-widget elementor-widget-text-editor\" data-id=\"5ac1c6a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>you can also activate and deactivate a virtual environment simply by typing:<\/p><p><code>activate environment1<\/code><\/p><p><code>deactivate<\/code><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f648f9f elementor-widget elementor-widget-text-editor\" data-id=\"f648f9f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You&#8217;ll need to activate your specific virtual environment before installing a specific module with a specific version. Once you are done working in that environment you can deactivate it and go back to base.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2a49155 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"2a49155\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">80) Groupby from itertools: (<i>Grouping Python Data<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3b5427d elementor-widget elementor-widget-text-editor\" data-id=\"3b5427d\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>If you have iterables with elements belonging to different groups, you can use itertools&#8217; groupby method to group them and process items in groups.<\/p><p>Here is an example:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-db1db78 elementor-widget elementor-widget-html\" data-id=\"db1db78\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from itertools import groupby\r\n\r\nlst = [(\"car\", \"Ferrari\"), (\"car\", \"Renault\"), (\"country\", \"France\"), (\"country\", \"New Zealand\"), (\"fruit\", \"Kiwi\")]\r\n\r\nfor i, group in groupby(lst, lambda x: x[0]):\r\n    for j in group:\r\n        print (\"{} is a {}.\".format(j[1], val))\r\n    print()<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6946121 elementor-widget elementor-widget-text-editor\" data-id=\"6946121\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>Ferrari is a fruit.\nRenault is a fruit.\n\nFrance is a fruit.\nNew Zealand is a fruit.\n\nKiwi is a fruit.<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e6ab7c7 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"e6ab7c7\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">81) Transposing Data: (<i>zip method<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-60db6f9 elementor-widget elementor-widget-text-editor\" data-id=\"60db6f9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This trick is simple yet genius and can be very useful sometimes.<\/p><p>You can combine zip function and <strong>* unpacking <\/strong>notation for *args appropriate objects.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3e88d18 elementor-widget elementor-widget-html\" data-id=\"3e88d18\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>mat = [[1, 2, 3], [1000, 2000, 3000]]\nzip(*mat)<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8f2ede4 elementor-widget elementor-widget-text-editor\" data-id=\"8f2ede4\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>[(1, 1000), (2, 2000), (3, 3000)]<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8fffc03 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"8fffc03\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">82) Working with Zipped files: (<i>ZipFile Library<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-dfd7bfa elementor-widget elementor-widget-text-editor\" data-id=\"dfd7bfa\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>As you get more and more proficient with Python, you start experimenting more and more cases. One of these cases is encountering zip files whether it&#8217;s data science, game development, finance or scripting, zip files are a very common part of the digital world.<\/p><p>Let&#8217;s check out how zipfile library can be a super convenient and quick solution for zip related tasks.<\/p><p>First you can import zipfile as below:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7b02ffc elementor-widget elementor-widget-html\" data-id=\"7b02ffc\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from zipfile import ZipFile\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d10ed62 elementor-widget elementor-widget-text-editor\" data-id=\"d10ed62\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>There are many useful methods to be used with zipfile, here are some common ones:<\/p><ul><li>Open: Opening with zipfile is more like creating a handle to work with. You can open a zip file in 2 ways: read; &#8220;r&#8221; and write; &#8220;w&#8221; depending on your use case.<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-71f71ee elementor-widget elementor-widget-html\" data-id=\"71f71ee\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from zipfile import ZipFile\n\nf = ZipFile(\"myarchive.zip\", \"r\")\nf = ZipFile(\"myarchive.zip\", \"w\")\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b107a41 elementor-widget elementor-widget-text-editor\" data-id=\"b107a41\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li>Get file names: You can have a list of all the files&#8217; names returned using <b>namelist()<\/b> method<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-32e6d88 elementor-widget elementor-widget-html\" data-id=\"32e6d88\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from zipfile import ZipFile\n\nf = ZipFile(\"myarchive.zip\", \"r\")\nprint(f.namelist())\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8cd51cc elementor-widget elementor-widget-text-editor\" data-id=\"8cd51cc\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>['app.html', 'credits.html', 'app.css', 'auth.css', 'bridge.css', 'history.css', 'd3dcompiler.dll']<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3086d44 elementor-widget elementor-widget-text-editor\" data-id=\"3086d44\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li>Extract files:<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1cddba3 elementor-widget elementor-widget-html\" data-id=\"1cddba3\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from zipfile import ZipFile\n\nf = ZipFile(\"myarchive.zip\", \"r\")\nf.extractall(\"directory\")\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ce4bf5b elementor-widget elementor-widget-text-editor\" data-id=\"ce4bf5b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li>Read &amp; Write:<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-aabcf25 elementor-widget elementor-widget-html\" data-id=\"aabcf25\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from zipfile import ZipFile\n\nf = ZipFile(\"myarchive.zip\", \"r\")\na=f.read(r\"FF\/app.html\")\nprint(a)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bbdabad elementor-widget elementor-widget-text-editor\" data-id=\"bbdabad\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li>Please note that during the write operation zipfile is specifically opened with &#8220;w&#8221; parameter.<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e1e0870 elementor-widget elementor-widget-html\" data-id=\"e1e0870\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from zipfile import ZipFile\n\nwith ZipFile(\"myarchive.zip\", \"w\") as f:\n    f.write(\"pricelist.txt\")\n    f.write(\"deliveries.xls\")\n\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d640069 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"d640069\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">83) Time library: (<i>More Time Functions<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6f9374b elementor-widget elementor-widget-text-editor\" data-id=\"6f9374b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Time library provides lots of time related functions and methods and is good to know whether you&#8217;re developing a website or apps and games or working with data science or trading financial markets. Time is essential in most development pursuits and Python&#8217;s standard time library comes very handy for that.<\/p><p>Let&#8217;s check out a few simple examples:<\/p><p>moment=time.strftime(&#8220;%Y-%b-%d__%H_%M_%S&#8221;,time.localtime())<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4c1b8e3 elementor-widget elementor-widget-html\" data-id=\"4c1b8e3\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import time\r\n\r\ntime_now=time.strftime(\"%H:%M:%S\",time.localtime())\r\nprint(time_now)\r\n\r\ndate_now=time.strftime(\"%Y-%b-%d\",time.localtime())\r\nprint(date_now)<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fa32925 elementor-widget elementor-widget-text-editor\" data-id=\"fa32925\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>21:47:43<br \/>2020-Jun-24<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8c42518 elementor-widget elementor-widget-image\" data-id=\"8c42518\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"662\" height=\"244\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/5ccc6511c0e9-Custom.jpg\" class=\"attachment-large size-large wp-image-10737\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/5ccc6511c0e9-Custom.jpg 662w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/5ccc6511c0e9-Custom-300x111.jpg 300w\" sizes=\"(max-width: 662px) 100vw, 662px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Cool tube clock showing current time<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bf486ad elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"bf486ad\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">84) getsizeof: (<i>Sys Library<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e645e45 elementor-widget elementor-widget-text-editor\" data-id=\"e645e45\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>getsizeof() method from Python&#8217;s sys library will tell you the size of a Python object in the memory. Let&#8217;s see an example:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-78311eb elementor-widget elementor-widget-html\" data-id=\"78311eb\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import sys\na=\"Paris\"\nb=sys.getsizeof(a)\nprint(b)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7c6037e elementor-widget elementor-widget-text-editor\" data-id=\"7c6037e\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>54<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a61f372 elementor-widget elementor-widget-text-editor\" data-id=\"a61f372\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The result is in <b>bytes.<\/b><\/p><p>Getsizeof() will give the size of any Python object whatsoever. Range object, byte object, reversed object, list object, dictionary object, list goes on.<\/p><p>Let&#8217;s create a huge list and see its size in bytes:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f9aa180 elementor-widget elementor-widget-html\" data-id=\"f9aa180\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import sys\na=range(1000000)\nb=sys.getsizeof(list(a))\nprint(b)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c56534a elementor-widget elementor-widget-text-editor\" data-id=\"c56534a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>9000112<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cfa6674 elementor-widget elementor-widget-text-editor\" data-id=\"cfa6674\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Wow, <strong>9MB in memory.\u00a0<\/strong>Talk about a big list!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5c0d3c5 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"5c0d3c5\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">85) Named Tuples: (<i>From Collections Library<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ae565b9 elementor-widget elementor-widget-text-editor\" data-id=\"ae565b9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Named Tuple is such a sophisticated data type and it lets you create exactly what the name says and more.<\/p><p>Namedtuple is a:<\/p><ul><li>Light object<\/li><li>Readable<\/li><li>Allows creating attributes<\/li><li>Callable by names<\/li><li>Comes with object notation<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7caac2b elementor-widget elementor-widget-html\" data-id=\"7caac2b\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from collections import namedtuple\n\nflights = namedtuple(\"flight\", \"price, distance\")\nUS = flights(2000,5000)\nIceland = flights(500,500)\nFrance = flights(1000,1000)\n\nprint(France.distance)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9fc6da1 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"9fc6da1\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">86) Animated Charts: (<i>Save as Gif or Mp4<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-83bf36c elementor-widget elementor-widget-text-editor\" data-id=\"83bf36c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Visualization is big in Python. Matplotlib is a well-known library for charts but something super fancy and useful for visualization purposes that goes unnoticed is animated charts possibility in Matplotlib Animations.<\/p><p>Although the function itself, which is FuncAnimation module from matplotlib.animation library, is straightforward itself, there are some parameters that can get confusing such as figure itself, update function for animation, saving options such as codecs, fps settings, FFMpegWriter, PillowWriter, saving as gif, saving as mp4 or avi etc.<\/p><p>We have 2 great tutorials that you can check out explaining:<\/p><p><a href=\"https:\/\/holypython.com\/how-to-create-matplotlib-animations-the-ultimate-guide\/\">How to create a Matplotlib Animation<\/a><\/p><p><a href=\"https:\/\/holypython.com\/how-to-save-matplotlib-animations-the-ultimate-guide\/\">How to save a Matplotlib Animation<\/a><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-eef8304 elementor-widget elementor-widget-image\" data-id=\"eef8304\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"360\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/a.gif\" class=\"attachment-full size-full wp-image-6882\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0936c72 elementor-widget elementor-widget-text-editor\" data-id=\"0936c72\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In short a matplotlib animation is created with 2 major pieces:<\/p><ul><li>Figure &#8211;<em>fig<\/em> here: a figure window (can be initialized as <strong>plt.figure<\/strong>)<\/li><li>Animation function &#8211;<em>animate<\/em> here below: an animation function that continuously updates the figure<\/li><\/ul><p>For a more detailed walkthrough please visit the individual Python animation tutorials mentioned above.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f828d5e elementor-widget elementor-widget-html\" data-id=\"f828d5e\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import random\nimport matplotlib\nimport matplotlib.pyplot as plt\nfrom matplotlib.animation import FuncAnimation\n\nfig = plt.figure(figsize=(15,15))\n\nx,y = [], []\nindex= count()\ndef animate(i):\n    x.append(next(index))\n    y.append(random.randint(2,20))\n    plt.style.use(\"ggplot\")    \n    plt.plot(x,y)\n\nani = FuncAnimation(fig, animate, interval=300)\nplt.show()\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8a293de elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"8a293de\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">87) All or any: (<i>or & and Alternatives<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a724d40 elementor-widget elementor-widget-text-editor\" data-id=\"a724d40\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><strong>Any<\/strong> &amp; <strong>all<\/strong> are similar to <strong>or<\/strong> &amp; <strong>and.<\/strong><\/p><ul><li>Any returns True when at least 1 of the statements is True<\/li><li>All returns True when all statements are True<\/li><\/ul><p>Here are some examples:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2a54d69 elementor-widget elementor-widget-html\" data-id=\"2a54d69\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>any([False, False, False])\nall([False, True, True])\nany([True, False, False])\nany([False, False, True])\nall([True, True, True])\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9a28694 elementor-widget elementor-widget-text-editor\" data-id=\"9a28694\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>False<br \/>False<br \/>True<br \/>True<br \/>True<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5e72191 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"5e72191\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">88) Recursive Functions: (<i>Functions calling themselves<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5b45b92 elementor-widget elementor-widget-text-editor\" data-id=\"5b45b92\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Recursion in programming is a very powerful algorithmic phenomenon that helps question to be solved by solving mini pieces of the problem and continuously feeding the answer or solution back to the problem.<\/p><p>Because of this nature, it goes hand in hand with concepts such as iteration (think <a href=\"https:\/\/holypython.com\/intermediate-python-lessons\/lesson-8-python-for-loop\/\">for loop<\/a> or <a href=\"https:\/\/holypython.com\/intermediate-python-lessons\/lesson-9-while-loop\/\">while loop<\/a>), yield statement (in Python), <a href=\"https:\/\/holypython.com\/beginner-python-lessons\/lesson-16-defining-functions\/\">user-defined functions<\/a>, <a href=\"https:\/\/holypython.com\/sorting-algorithms\/\">algorithms<\/a>.<\/p><p>Recursive programming is a broad subject and it can go well beyond these Python concepts but solving a problem within Python&#8217;s syntax and structure can also be infinitely interesting at the micro level.<\/p><p>Let&#8217;s look at a commonly known number sequence to demonstrate a simple recursion idea in Python:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-82b04f1 elementor-widget elementor-widget-text-editor\" data-id=\"82b04f1\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Fibonacci number is calculated by adding 2 numbers preceding the current Fibonacci number. When it&#8217;s continuously done it gives Fibonacci Sequence:<\/p><p>Fib(n-2) + Fib(n-1) = Fib(n)<\/p><p>So it goes,<\/p><p>0 | 1 | 1 | 2 | 3 | 5 | 8 | 13 | 21 | 34 | 55 &#8230;.<\/p><p>Let&#8217;s put it in code:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-959c353 elementor-widget elementor-widget-html\" data-id=\"959c353\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>def fibo(x):\n    \n    if x <= 1:\n        return x\n    else:\n        return fibo(x-1) + fibo(x-2)\n    \nfor i in range(40):\n    print(fibo(i), end=\" || \")\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5b7b8db elementor-widget elementor-widget-text-editor\" data-id=\"5b7b8db\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This code will return 1 for fibo(1) and 0 for fibo(0). After that it starts an infinite recursion. fibo(2) is fibo(1)+fibo(0) and fibo(3) is fibo(2)+fibo(1).<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-716c265 elementor-widget elementor-widget-text-editor\" data-id=\"716c265\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>0 || 1 || 1 || 2 || 3 || 5 || 8 || 13 || 21 || 34 || 55 || 89 || 144 || 233 || 377 || 610 || <br \/>987 || 1597 || 2584 || 4181 || 6765 || 10946 || 17711 || 28657 || 46368 || 75025 || 121393 || <br \/>196418 || 317811 || 514229 || 832040 || 1346269 || 2178309 || 3524578 || 5702887 || 9227465 || <br \/>14930352 || 24157817 || 39088169 || 63245986 || <\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3363916 elementor-widget elementor-widget-text-editor\" data-id=\"3363916\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>To check out a <a href=\"https:\/\/holypython.com\/beginner-python-lessons\/lesson-1-print\/\">Python lesson about advanced parameters of print() function<\/a> you can click the link.<\/p><p>You can also check out this\u00a0<a href=\"https:\/\/holypython.com\/insertion-sort-algorithm-python-code\/\">recursive algorithm demonstration with visualization<\/a>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ef2462c elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"ef2462c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">89) Cache results with decorators: (<i>Efficient Functions<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ed27ab3 elementor-widget elementor-widget-text-editor\" data-id=\"ed27ab3\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>There is a great way to cache functions with decorators in Python. Caching will help save time and precious resources when there is an expensive function at hand.<\/p><p>Implementation is easy, just import <strong>lru_cache<\/strong> from <strong>functools<\/strong> library and decorate your function using <strong>@lru_cache.<\/strong><\/p><p>Here is an example:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a2190a3 elementor-widget elementor-widget-html\" data-id=\"a2190a3\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef fibo(x):\n    if x <= 1:\n        return x\n    else:\n        return fibo(x-1) + fibo(x-2)\n\nfor i in range(50):\n    print(fibo(i), end=\"|\")\n\nprint(\"\\n\\n\", fibo.cache_info())\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d91664f elementor-widget elementor-widget-text-editor\" data-id=\"d91664f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Furthermore, you can also ask for a cache status report using\u00a0<strong>cache_info().<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8c7b93b elementor-widget elementor-widget-text-editor\" data-id=\"8c7b93b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>0|1|1|2|3|5|8|13|21|34|55|89|144|233|377|610|987|1597|2584|4181|6765|<br \/>10946|17711|28657|46368|75025|121393|196418|317811|514229|832040|<br \/>1346269|2178309|3524578|5702887|9227465|14930352|24157817|39088169|<br \/>63245986|102334155|165580141|267914296|433494437|701408733|<br \/>1134903170|1836311903|2971215073|4807526976|7778742049|<\/pre><pre>CacheInfo(hits=96, misses=50, maxsize=None, currsize=50)<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-412d8c9 elementor-widget elementor-widget-text-editor\" data-id=\"412d8c9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><em><strong>Hits<\/strong> and <strong>misses<\/strong> show cache <strong>hits<\/strong> and cache <strong>misses<\/strong> that occurred during operation.\u00a0<\/em><\/p><p><em>Cache <strong>hit<\/strong> roughly denotes when a value is looked up in the cache and is found in the cache and cache <strong>miss<\/strong> is when a value is looked up but can&#8217;t be found in the cache.<\/em><\/p><p><em><strong>Currsize<\/strong> signifies the current size of cache or in other words how many items have been cached, in this case 50, basically all of them, and <strong>maxsize<\/strong> is the maximum allowed items allowed to be cached, in this case None because we specified <b>maxsize <\/b>to be None in the beginning.<\/em><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-e246e80 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e246e80\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-612c01e\" data-id=\"612c01e\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-7f93a89 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"7f93a89\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">90) Textblob: (<i>Sentiment Analysis<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2d2d017 elementor-widget elementor-widget-text-editor\" data-id=\"2d2d017\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Sentiment analysis is a term used to refer to the techniques that aims to extract sentiments, emotions or tone from a text. With the advancements in computation power and technology and accumulation of text (social media, online books, news, translation of ancient scripts etc.) Natural language processing (NLP) has become a very interesting and significant field in the last decade.<\/p><p>Textblob is a fantastic library that can be used for sentiment analysis and more. Sentiment can be used to tell the features of a text such as tone positivity, subjectivity, objectivity, hopefulness, kindness, explicit language, grammar analysis, translation,\u00a0 spelling check, etc etc.<\/p><p>This method is currently being used by multiple hedge funds to analyze social media and online news to identify trading opportunities and analyze companies, markets, indexes, economies, stocks and commodities.<\/p><p>It can also be used to analyze political stability, global events, crisis management, books, articles, social media profiles and more.<\/p><p>Here is a simple demonstration from a random book:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-002ea2d elementor-widget elementor-widget-html\" data-id=\"002ea2d\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from textblob import TextBlob\n\nf = r\"c:\/\/Users\/USA\/Desktop\/asd.txt\"\nfile = open(f, \"r\", encoding=\"utf8\")\ndata= (file.read())\n\nblob = TextBlob(data)\n\nb=blob.sentences\nprint(b[0])\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0ee876a elementor-widget elementor-widget-text-editor\" data-id=\"0ee876a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>Spending time together is like playing in the anteroom of heaven.<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7fadcf6 elementor-widget elementor-widget-text-editor\" data-id=\"7fadcf6\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li>First TextBlob module needs to be imported<\/li><li>Then a blob object needs to be created with the text being analyzed<\/li><li>And you can start sentiment analysis right away after that<\/li><li>There are already lots of convenient methods and attributes included such as:<ul><li>.tags<\/li><li>.noun_phrases<\/li><li>.sentiment<\/li><li>.sentiment.polarity<\/li><li>.words<\/li><li>.sentences<\/li><li>.lemmatize (grouping similar words for analysis based on context)<\/li><li>.definition<\/li><li>.correct()<\/li><li>.spellcheck()<\/li><li>.words.count()<\/li><li>.ngrams()<\/li><\/ul><\/li><li>\u00a0<\/li><\/ul><div>Note: If you don&#8217;t have textblob library installed, you can refer to <a href=\"https:\/\/holypython.com\/installing-pip-packages-with-anaconda\/\">this <\/a>installation tutorial.<\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1b9cb43 elementor-widget elementor-widget-text-editor\" data-id=\"1b9cb43\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>.sentences returns a list of sentences from the text and here we&#8217;re printing only the 1st sentence (index 0). Here is what .tags will return:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b0fd9b4 elementor-widget elementor-widget-html\" data-id=\"b0fd9b4\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>b=blob.tags\nprint(b[:5])\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f350b1c elementor-widget elementor-widget-text-editor\" data-id=\"f350b1c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>[('Spending', 'NN'), ('time', 'NN'), ('together', 'RB'), ('is', 'VBZ'), ('like', 'IN')]<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9b10805 elementor-widget elementor-widget-html\" data-id=\"9b10805\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>b=blob.sentiment\nprint(b[:5])\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8c22e09 elementor-widget elementor-widget-text-editor\" data-id=\"8c22e09\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>Sentiment(polarity=0.0059523809523809494, subjectivity=0.5603174603174603)<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-997fafc elementor-widget elementor-widget-text-editor\" data-id=\"997fafc\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Polarity here refers to a sentiment range between -1 and +1, from most <b>negative<\/b> to the most <b>positive<\/b>. Subjectivity can take a value between 0 and +1, 1 being the <b>most subjective<\/b> text possible while 0 signifies maximum <b>objectivity<\/b>.<\/p><p>Let&#8217;s see the last 5 words this time:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-745177d elementor-widget elementor-widget-html\" data-id=\"745177d\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>b=blob.words[-1:-6:-1]\nprint(b)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f98d646 elementor-widget elementor-widget-text-editor\" data-id=\"f98d646\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>['mountains', 'huge', 'become', 'now', 'love']<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-96119a5 elementor-widget elementor-widget-text-editor\" data-id=\"96119a5\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>And definition of the last word:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c90df61 elementor-widget elementor-widget-html\" data-id=\"c90df61\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>b=blob.words[-1].definitions\nprint(b)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1402c7a elementor-widget elementor-widget-text-editor\" data-id=\"1402c7a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>['a land mass that projects well above its surroundings; higher than a hill', <\/pre><pre>\"(often followed by `of') a large number or amount or extent\"]<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5426de8 elementor-widget elementor-widget-text-editor\" data-id=\"5426de8\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can also check out this <a href=\"https:\/\/holypython.com\/sentiment-analysis-in-python-w-textblob-nltk\/\">sentiment analysis tutorial with textblob<\/a> for more examples.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1156e0b elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"1156e0b\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">91) Kwargs: (<i>Arguments for named sequences<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-771f061 elementor-widget elementor-widget-text-editor\" data-id=\"771f061\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>**kwargs and *args are function arguments that can be very useful.<\/p><p>They are quite underused and often under-understood as well. (Sorry couldn&#8217;t resist that)<\/p><p>Let&#8217;s try to explain what kwargs are and how to use them.<\/p><ul><li>While *args are used to pass arguments at an unknown amount to functions, **kwargs are used to do the same but with named arguments.<\/li><li>So, if *args is a list being passed as an argument, you can think of **kwargs as a dictionary that&#8217;s being passed as an argument to a function.<\/li><li>You can use arguments as you wish as long as you follow the correct order which is: <strong>arg1, arg2, *args, **kwargs.\u00a0<\/strong>It&#8217;s okay to use only one of those but you can&#8217;t mix the order, for instance, you can&#8217;t have: <strong>function(**kwargs, arg1)<\/strong>, that&#8217;d be a major faux pas in Python.<\/li><li>Another example: You can do <strong>function(*args,**kwargs)<\/strong> since it follows the correct order.<\/li><li>\u00a0<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1e590b4 elementor-widget elementor-widget-text-editor\" data-id=\"1e590b4\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here is an example. Let&#8217;s say satelites are given with their names and weight in tons in dictionary format. Code prints their weight as kilograms along with their names.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5c9e5ef elementor-widget elementor-widget-html\" data-id=\"5c9e5ef\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>def payloads(**kwargs):\n    for key, value in kwargs.items():\n        print( key+\" |||\", float(value)*1000)\n\npayloads(NavSat1 = '2.8', BaysatG2 = '5')\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e7aba74 elementor-widget elementor-widget-text-editor\" data-id=\"e7aba74\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>NavSat1 ||| 2800.0<br \/>BaysatG2 ||| 5000.0<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-08f525c elementor-widget elementor-widget-text-editor\" data-id=\"08f525c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Since the function above would work for any number of dictionary keys, **kwargs makes perfect sense rather than passing arguments with a fixed amount.<\/p><p>Also <b>**\u00a0<\/b>syntax can be used to unpack while calling a function. Check out this example:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c981739 elementor-widget elementor-widget-html\" data-id=\"c981739\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>def payloads(**kwargs):\n    for key, value in kwargs.items():\n        print( key+\" |||\", float(value)*1000)\n\nsats={\"Tx211\":\"2\", \"V1\":\"0.65\"}\npayloads(**sats)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a804e3a elementor-widget elementor-widget-text-editor\" data-id=\"a804e3a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>Tx211 ||| 2000.0<br \/>V1 ||| 650.0<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8357c8b elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"8357c8b\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">92) Compile a regex formula: (<i>Advanced Regex<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0500726 elementor-widget elementor-widget-text-editor\" data-id=\"0500726\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can also compile regular expressions in Python.<\/p><p>Regex has a massive place in working with all kinds of text, database queries, strings, search engine queries, tables, web data etc.<\/p><p>Python comes with a standard regular expression library called <strong>re.\u00a0<\/strong>If you&#8217;re new to regex and would like to learn more you can check out this extensive:<\/p><p><a href=\"https:\/\/holypython.com\/advanced-python-lessons\/lesson-6-regular-expressions\/\">Python Regular Expression Tutorial<\/a><\/p><p>and<\/p><p><a href=\"https:\/\/holypython.com\/advanced-python-exercises\/project-regular-expressions-regex\/\">Python Regular Expression Exercises<\/a> (Online &amp; Interactive)<\/p><p>So in this tip we will check out how regex can be compiled and the benefits of doing so.<\/p><p>Normally, when you use a regex expression Python will compile it during the execution of your program and it won&#8217;t really make a difference if regex is compiled before hand or not. Especially since Python also caches regular expressions the performance benefits of separately compiling regex is not expected to be significant.<\/p><p>However, some main benefits of compiling regex are reusability and readability.<\/p><p>On top of that it can make sense to compile some regex expressions ahead of execution so that compilation is not done at a random or even worse critical moment when running the program.<\/p><p>Check out this simple example to understand how regex can be compiled in Python:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5a04128 elementor-widget elementor-widget-text-editor\" data-id=\"5a04128\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><em>Regular Expression without compiling:<\/em><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-66b77a1 elementor-widget elementor-widget-html\" data-id=\"66b77a1\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import re\n\nstr='''Chuck Norris can divide by zero.\nWhen Chuck Norris falls in water, Chuck Norris doesn't get wet. Water gets Chuck Norris.\nChuck Norris once visited the Virgin Islands. They are now The Islands.'''\n\nresult2 = (re.match('[A-Z][a-z]*\\s\\S*', str))\nprint((result2))\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-49c00e9 elementor-widget elementor-widget-text-editor\" data-id=\"49c00e9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><em>Regular Expression Compiled Example:<\/em><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e6624ed elementor-widget elementor-widget-html\" data-id=\"e6624ed\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import re\n\nstr='''Chuck Norris can divide by zero.\nWhen Chuck Norris falls in water, Chuck Norris doesn't get wet. Water gets Chuck Norris.\nChuck Norris once visited the Virgin Islands. They are now The Islands.'''\n\nquery = re.compile('[A-Z][a-z]*\\s\\S*')\nresult1 = (query.match(str))\n\nprint((result1))<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6a83383 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"6a83383\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">93) Create a File Server: (<i>A Surprising One Liner<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e80e252 elementor-widget elementor-widget-text-editor\" data-id=\"e80e252\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This one is kind of well-known. Still very impressive nevertheless.<\/p><p>At the comfort of your command prompt (we recommend Anaconda Prompt), you can create an HTTP server with a tiny one line Python command like below:<\/p><p><code>python -m http.server 8000<\/code><\/p><p>Number in the end here is the Port Number.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-76c6f92 elementor-widget elementor-widget-image\" data-id=\"76c6f92\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"613\" height=\"345\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/python-https-server.jpg\" class=\"attachment-large size-large wp-image-10762\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/python-https-server.jpg 613w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/python-https-server-300x169.jpg 300w\" sizes=\"(max-width: 613px) 100vw, 613px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">python https server<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-20b3bcf elementor-widget elementor-widget-text-editor\" data-id=\"20b3bcf\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Server will start immediately. If you&#8217;d like to kill the server just pres <strong>Ctrl+C\u00a0<\/strong>and server will be interrupted as above or you can just close the Prompt Window.<\/p><p>If you&#8217;d like to make sure you can type <strong>ps\u00a0<\/strong>from the Command Prompt to see all the processes. Scroll up to <strong>P\u00a0<\/strong>and you will see a Python process when the server is running which will be shut down after you stop the server.<\/p><p>Please note that if you have other instances of Python running such as Spyder or any Python IDE or Python itself, these processes will also appear under Python in the list.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-14f7dfd elementor-widget elementor-widget-image\" data-id=\"14f7dfd\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"689\" height=\"203\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/python-https-server-process-list.jpg\" class=\"attachment-large size-large wp-image-10764\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/python-https-server-process-list.jpg 689w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/python-https-server-process-list-300x88.jpg 300w\" sizes=\"(max-width: 689px) 100vw, 689px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">python https server process list<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d04c88c elementor-widget elementor-widget-text-editor\" data-id=\"d04c88c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li>You can access you Python file server by navigating to <strong>localhost:8000<\/strong> (Or whatever port you chose) from your browser&#8217;s address bar.<\/li><li>It&#8217;d be wise to open the server on a dedicated not-so-important folder somewhere in your computer. i.e.: You can create a new folder on your desktop, navigate to that directory using <strong>cd<\/strong> command and start the server within there.<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-90ffbd4 elementor-widget elementor-widget-image\" data-id=\"90ffbd4\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"857\" height=\"569\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/Python-file-server-directory.jpg\" class=\"attachment-large size-large wp-image-10766\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/Python-file-server-directory.jpg 857w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/Python-file-server-directory-300x199.jpg 300w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/Python-file-server-directory-768x510.jpg 768w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Python file server directory<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9f8dd2a elementor-widget elementor-widget-text-editor\" data-id=\"9f8dd2a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can get Spyder inside Anaconda Individual Package for free <a href=\"https:\/\/www.anaconda.com\/products\/individual\">here<\/a>.<\/p><p>Or if you wish you can also get Spyder IDE individually from <a href=\"https:\/\/www.spyder-ide.org\">this link<\/a>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ae6f79d elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"ae6f79d\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">94) Enum Class: (<i>Members with unique ID values<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e14b835 elementor-widget elementor-widget-text-editor\" data-id=\"e14b835\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here is another classy approach from Python, no pun intended.\u00a0Python&#8217;s enum class will let you create enum object members with constant and unique values which then can be listed, compared or used for identification.\u00a0<\/p><p>Enum classes are also iterable so they can be iterated as well:<\/p><p>Here is a simple example:\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-45e320a elementor-widget elementor-widget-html\" data-id=\"45e320a\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from enum import Enum\n\nclass sports(Enum):\n    skiing = 0\n    soccer = 1\n    running = 2\n    football = 3\n    golf = 4\n    swimming = 5\n    \n    \nprint(sports.golf)\nprint(repr(sports.golf))\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3555f5f elementor-widget elementor-widget-text-editor\" data-id=\"3555f5f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>sports.golf<br \/>&lt;sports.golf: 4&gt;<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-44a5c23 elementor-widget elementor-widget-text-editor\" data-id=\"44a5c23\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Python enum class iteration example:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1cd3a58 elementor-widget elementor-widget-html\" data-id=\"1cd3a58\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>for i in sports():\n    print(i)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-96547b7 elementor-widget elementor-widget-text-editor\" data-id=\"96547b7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>&lt;sports.skiing: 0&gt;<br \/>&lt;sports.soccer: 1&gt;<br \/>&lt;sports.running: 2&gt;<br \/>&lt;sports.football: 3&gt;<br \/>&lt;sports.golf: 4&gt;<br \/>&lt;sports.swimming: 5&gt;<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b3d1fd9 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"b3d1fd9\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">95) Connect to Database: (<i>SQLite<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e218425 elementor-widget elementor-widget-text-editor\" data-id=\"e218425\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Database is such a powerful concept to store data. Apps use it, software uses it, websites use it. It&#8217;s not that hard and you can also use it.<\/p><p>But then when you combine Database programming with Python, that&#8217;s real power.<\/p><p>SQlite is a nice open-source application that works well with Python.<\/p><p>All you need to do is type a few Python codes and implement your SQL code inside. It will be something like this:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-25843a0 elementor-widget elementor-widget-html\" data-id=\"25843a0\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import sqlite3\n\nq = sqlite3.connect('Mydatabase.db')\ncursor = q.cursor()\n\ncursor.execute('SELECT id, name FROM Prices')\ndata = cursor.fetchall()\nfor i in data:\n    print(i)\n\ncursor.close()\n\nq.close()\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-931cf0f elementor-widget elementor-widget-text-editor\" data-id=\"931cf0f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ol><li>First connect to database via sqlite3 <strong>(sqlite3.connect(&#8216;Mydatabase.db&#8217;))<\/strong><\/li><li>Create a cursor <strong>(q.cursor())<\/strong><\/li><li>Then, <strong>cursor.execute<\/strong> for executing Database Commands.<\/li><li><strong>.fetchall()<\/strong> to get data from the <b>Database Rows<\/b>\u00a0<\/li><li>Finally close the cursor and terminate the connection (<strong>cursor.close()<\/strong> and <strong>q.close()<\/strong>)<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-43ecc1d elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"43ecc1d\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">96) StringIO, cStringIO and BytesIO: (<i>Python Streams<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-341ee64 elementor-widget elementor-widget-text-editor\" data-id=\"341ee64\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>These very potent, practical but unused methods can mean the difference between hardcore performance and inefficient operations.<\/p><p>Generally Python stream is a file-like object that exists in the Ram of the computer instead of the Disk IO. Ram is much faster than Disk and can be perfect for parts of the program that&#8217;s running.<\/p><p>That&#8217;s why lots of software has some kind of Ram usage and you can implement it too.<\/p><ul><li><b>StringIO<\/b> is used with unicode objects (like strings) and it will accept any string with <b>Unicode\u00a0<\/b>encoding<\/li><li><b>BytesIO<\/b> is used with byte data (binary input)<\/li><li><b>cStringIO <\/b>is like <b>StringIO <\/b>since it&#8217;s a <b>C<\/b> implementation<b>\u00a0<\/b>but there is a catch, cString won&#8217;t accept any string that can not be encoded as plain <b>Ascii, <\/b>which can be limiting depending on the situation.<\/li><\/ul><div>All of these methods will provide a file like object to write data.<\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2297b24 elementor-widget elementor-widget-html\" data-id=\"2297b24\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import StringIO\n\nstr = \"Hello World\"\nfile = StringIO.StringIO(str)\n\nprint (file.read())\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8667287 elementor-widget elementor-widget-text-editor\" data-id=\"8667287\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>Hello World<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-463447d elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"463447d\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">97) Work with gzip files in Python: (<i>gzip library<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0ad01d8 elementor-widget elementor-widget-text-editor\" data-id=\"0ad01d8\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Gzip or gnu is a compression algorithm that can provide lots of compression benefits with large files. You might have seen it before as a file which uses .gz extension. Since gzip only works for a single file you might also have seen the tar archive solution which combines multiple files before creating gzip compression resulting in a tar.gz (or tgz) file.<\/p><p>Python has a great gzip library that makes working with gzip files a breeze.<\/p><p>Here is a super simple demonstration of compressing a Python list:\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b73c5a3 elementor-widget elementor-widget-html\" data-id=\"b73c5a3\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import gzip\n\nstr = b\"Hello World\"\nc_str = gzip.compress(str)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d726e38 elementor-widget elementor-widget-text-editor\" data-id=\"d726e38\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>That was too easy because our string was in byte format already <strong>b&#8221;&#8221;.<\/strong><\/p><p>Because compress() method takes byte data only. So, sometimes you might need to make that conversion but it&#8217;s not that complicated once you know it.<\/p><p>Here is another example where a regular string is &#8220;prepared&#8221; for compression:<\/p><ol><li>First, string is going to be converted to bytes using bytes() function\u00a0<\/li><li>And second,\u00a0<b>&#8220;utf8&#8221; <\/b>is passed as encoding parameter in the bytes function.<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-42ede53 elementor-widget elementor-widget-html\" data-id=\"42ede53\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import gzip\nstr = \"Hello World\"\nstr = bytes(str, \"utf8\")\nc = gzip.compress(str)\nprint(c)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2ae89c7 elementor-widget elementor-widget-text-editor\" data-id=\"2ae89c7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>So, what if you want to compress Python objects such as lists, dictionaries, tuples or files and images. In each case you will need to do appropriate conversions so that data is ready for compression. Here is an idea to compress a list: First it&#8217;s converted to string and then compressed. Similar methods can be used with JSON method.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7ca1128 elementor-widget elementor-widget-html\" data-id=\"7ca1128\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import gzip\n\nlst = [\"kiwi\",\"apple\",\"banana\"]\nlst = str(lst)\nlst = bytes(lst, \"utf8\")\nc=gzip.compress(lst)\nprint(c)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-11334c9 elementor-widget elementor-widget-text-editor\" data-id=\"11334c9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Decompression part is the reverse of a compression process and somewhat more straightforward:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5990754 elementor-widget elementor-widget-html\" data-id=\"5990754\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import gzip\ndec_lst = gzip.decompress(c_lst)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-808e650 elementor-widget elementor-widget-text-editor\" data-id=\"808e650\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Finally, you can also use open() method to open gzip files and work with them.<\/p><p>open with structure can also be useful in this case:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-80767fc elementor-widget elementor-widget-html\" data-id=\"80767fc\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>with gzip.open(\"textfile.txt.gz\", \"rb\") as file:\n\tdata = file.read()\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7ff0b3b elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"7ff0b3b\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">98) Memory Management: (<i>getrefcount method<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-21eb3af elementor-widget elementor-widget-text-editor\" data-id=\"21eb3af\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>getrefcount will show how many times an object is used in the memory. It&#8217;s a fantastic tool that can be used for memory management in any program and it&#8217;s very convenient too.\u00a0<\/p><p>Getrefcount will calculate the object usage at a low level ByteCode so it can tend to be higher than expected. For instance when you print a value that value is actually processed multiple times in the background inside the print function itself and getrefcount also counts the instance when the value is called with getrefcount method itself. So, it&#8217;s safe to say that the count will actually always be at least 1 time higher than expected.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-854f7a8 elementor-widget elementor-widget-text-editor\" data-id=\"854f7a8\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here is a code to show how many times alphanumeric characters are referenced in a random code:<\/p><p><em>It makes sense to see that x, i and y are so frequently utilized.<\/em><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e31f594 elementor-widget elementor-widget-html\" data-id=\"e31f594\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import sys\nimport matplotlib.pyplot as plt\n \n#string with all character letters\nstr = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\"\nx_ax = [sys.getrefcount(i) for i in str]\ny_ax = range(len(str))\nGraph = plt.figure(figsize=(250,150))\n\nplt.bar(y_ax, x_ax, align='center', color=\"orange\")\nplt.xticks(y_ax, str)\n\nplt.xlabel(\"Character\")\nplt.ylabel('sys.getrefcount(str)')\n \nGraph.show()\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a786133 elementor-widget elementor-widget-image\" data-id=\"a786133\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"361\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/character-freq-Custom-1-1024x361.jpg\" class=\"attachment-large size-large wp-image-10887\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/character-freq-Custom-1-1024x361.jpg 1024w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/character-freq-Custom-1-300x106.jpg 300w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/character-freq-Custom-1-768x271.jpg 768w, https:\/\/holypython.com\/wp-content\/uploads\/2020\/06\/character-freq-Custom-1.jpg 1058w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6082a20 elementor-widget elementor-widget-text-editor\" data-id=\"6082a20\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This code will show reference counts for 2 random variables: First an integer that gets increased by 1, second, a random word that&#8217;s not likely to be used anywhere else in the backend of the functions (Heritage).<\/p><p>Interestingly first variable (integer 10) is referenced 309 (minus one) times in the kitchen of this little program. Second variable is never used except our assignment and reference count attempt which adds up to 3 times. Cool trick?<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-577a9e4 elementor-widget elementor-widget-html\" data-id=\"577a9e4\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>a_val = 10\na_val += 1\n\nb_val = \"Heritage\"\n\na = sys.getrefcount(a_val)\nb = sys.getrefcount(b_val)\n\nprint(a, b, sep=\"\\n\")\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-051694c elementor-widget elementor-widget-text-editor\" data-id=\"051694c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>309<br \/>3<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-84399e0 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"84399e0\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">99) os.environ: (<i>environment variables<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1df747e elementor-widget elementor-widget-text-editor\" data-id=\"1df747e\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>environ is a very cool module from Python&#8217;s default os library.<\/p><p>You can access all environment variables in your operating system using os.environ.<\/p><p>It works in a dictionary format and lists all the variables. Let&#8217;s see:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-97a9660 elementor-widget elementor-widget-html\" data-id=\"97a9660\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import os\nprint(os.environ)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-728a3a9 elementor-widget elementor-widget-text-editor\" data-id=\"728a3a9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Above code will give you a raw and messy output to the human eye. But, you can specify which data you&#8217;d like to extract with os.environ as well.<\/p><p>Since it&#8217;s in dictionary we can tweak the code a little bit to make everything more readable, also it&#8217;s an opportunity to use the pprint library:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b0c127b elementor-widget elementor-widget-text-editor\" data-id=\"b0c127b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>{&#8216;ALLUSERSPROFILE&#8217;: &#8216;C:\\\\ProgramData&#8217;,<br \/>&#8216;APPDATA&#8217;: &#8216;C:\\\\Users\\\\ABC\\\\AppData\\\\Roaming&#8217;,<br \/>&#8216;CLICOLOR&#8217;: &#8216;1&#8217;,<br \/>&#8216;COMMONPROGRAMFILES&#8217;: &#8216;C:\\\\Program Files\\\\Common Files&#8217;,<br \/>&#8216;COMMONPROGRAMFILES(X86)&#8217;: &#8216;C:\\\\Program Files (x86)\\\\Common Files&#8217;,<br \/>&#8216;COMMONPROGRAMW6432&#8217;: &#8216;C:\\\\Program Files\\\\Common Files&#8217;,<br \/>&#8216;COMPUTERNAME&#8217;: &#8216;DESKTOP-465GJRJ&#8217;,<br \/>&#8216;CONDA_PREFIX&#8217;: &#8216;C:\\\\Anaconda3&#8217;,<br \/>&#8216;DRIVERDATA&#8217;: &#8216;C:\\\\Windows\\\\System32\\\\Drivers\\\\DriverData&#8217;,<br \/>&#8216;GIT_PAGER&#8217;: &#8216;cat&#8217;,<br \/>&#8216;HOMEDRIVE&#8217;: &#8216;C:&#8217;,<br \/>&#8216;HOMEPATH&#8217;: &#8216;\\\\Users\\\\ABC&#8217;,<br \/>&#8230;<\/p><p>&#8216;PROCESSOR_ARCHITECTURE&#8217;: &#8216;AMD64&#8217;,<br \/>&#8216;PROCESSOR_IDENTIFIER&#8217;: &#8216;Intel64 Family 6 Model 158 Stepping 10, GenuineIntel&#8217;,<br \/>&#8216;PROCESSOR_LEVEL&#8217;: &#8216;6&#8217;,<br \/>&#8216;PROCESSOR_REVISION&#8217;: &#8216;gxxa&#8217;,<br \/>&#8216;PROGRAMDATA&#8217;: &#8216;C:\\\\ProgramData&#8217;,<br \/>&#8216;PROGRAMFILES&#8217;: &#8216;C:\\\\Program Files&#8217;,<br \/>&#8216;PROGRAMFILES(X86)&#8217;: &#8216;C:\\\\Program Files (x86)&#8217;,<br \/>&#8216;Files\\\\WindowsPowerShell\\\\Modules;C:\\\\WINDOWS\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\Modules&#8217;,<br \/>&#8230;<br \/>&#8216;SYSTEMDRIVE&#8217;: &#8216;C:&#8217;,<br \/>&#8216;SYSTEMROOT&#8217;: &#8216;C:\\\\WINDOWS&#8217;,<br \/>&#8216;TMP&#8217;: &#8216;C:\\\\Users\\\\ABC\\\\AppData\\\\Local\\\\Temp&#8217;,<br \/>&#8216;USERDOMAIN&#8217;: &#8216;DESKTOP-465GJRJ&#8217;,<br \/>&#8216;USERDOMAIN_ROAMINGPROFILE&#8217;: &#8216;DESKTOP-465GJRJ&#8217;,<br \/>&#8216;USERNAME&#8217;: &#8216;ABC&#8217;,<br \/>&#8216;USERPROFILE&#8217;: &#8216;C:\\\\Users\\\\ABC&#8217;,<br \/>&#8216;WINDIR&#8217;: &#8216;C:\\\\WINDOWS&#8217;}<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d2eb2f2 elementor-widget elementor-widget-html\" data-id=\"d2eb2f2\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import os\nimport pprint\nprint(os.environ)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-051eea7 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"051eea7\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">100) Serialization: (<i>pickle & Json<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9acbfe0 elementor-widget elementor-widget-text-editor\" data-id=\"9acbfe0\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Sometimes you may need to save your Python object locally for later use or Network transfers. Python has fantastic libraries for serialization such as Json and\u00a0<strong>Pickle.<\/strong><\/p><p>Serialization is storing data structures in the program so they don&#8217;t just disappear after the program is terminated.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-563f12b elementor-widget elementor-widget-text-editor\" data-id=\"563f12b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>There is also marshal library but it&#8217;s more primitive and can&#8217;t handle certain techniques such as class instances and recursion. Marshal is closer to json in its scope of serialization.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c60459a elementor-widget elementor-widget-text-editor\" data-id=\"c60459a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>So, when would you use pickle, cpickle, json or ujson?<\/p><p>cpickle and ujson are faster versions of respective libraries that take advantage of C implementations in Python. So they&#8217;d always be favorable for speed reasons.<\/p><p>Apart from that, json is a more secure and readable version of serialization than pickle which comes at a cost of speed.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-10c2e89 elementor-widget elementor-widget-text-editor\" data-id=\"10c2e89\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>While you can take care of almost any data structure in Python with <strong>Json\u00a0<\/strong>it gets inefficient with large files or uncommon objects. Pickle on the other hand operates in a sweet spot where you&#8217;d like to work with large files (multiple GBs) and still don&#8217;t want to be bothered with database solutions.<\/p><p>The thing is depending on your application, you may have to watch out for security vulnerabilities pickle introduces to the system so it&#8217;s usually wise to seek out json or database solutions before resorting to pickle when possible.<\/p><p>You can check out our <a href=\"https:\/\/holypython.com\/advanced-python-lessons\/lesson-1-json-in-python\/\">JSON Tutorial<\/a> explaining JSON solutions in Python.<\/p><p>Here is a quick pickle serialization and deserialization:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-959a71f elementor-widget elementor-widget-html\" data-id=\"959a71f\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import pickle\n\nlst = [\"LAX\", \"LGA\", \"DEN\", \"SFO\", \"JFK\", \"MIA\"]\na = pickle.dumps(lst)\n\nprint(a)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4ad77d7 elementor-widget elementor-widget-text-editor\" data-id=\"4ad77d7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>b'\\x80\\x03]q\\x00(X\\x03\\x00\\x00\\x00LAXq\\x01X\\x03\\x00\\x00\\x00LGAq\\x02X\\x03\\x00\\x00\\x00DENq\\<br \/>x03X\\x03\\x00\\x00\\x00SFOq\\x04X\\x03\\x00\\x00\\x00JFKq\\x05X\\x03\\x00\\x00\\x00MIAq\\x06e.'<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a00da96 elementor-widget elementor-widget-html\" data-id=\"a00da96\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>print(pickle.loads(a))\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-169bb5f elementor-widget elementor-widget-text-editor\" data-id=\"169bb5f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>['LAX', 'LGA', 'DEN', 'SFO', 'JFK', 'MIA']<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-a1347cc elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a1347cc\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-cd8953f\" data-id=\"cd8953f\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-8d45dd3 elementor-section-content-middle elementor-section-height-min-height elementor-section-boxed elementor-section-height-default\" data-id=\"8d45dd3\" data-element_type=\"section\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-bf12323\" data-id=\"bf12323\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9b46641 elementor-widget elementor-widget-heading\" data-id=\"9b46641\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Python Tips &amp; Tricks (Bonus Parts)<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d3f461c elementor-widget elementor-widget-heading\" data-id=\"d3f461c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Various Levels<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4766957 elementor-widget elementor-widget-heading\" data-id=\"4766957\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">HolyPython.com<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-9328240 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"9328240\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Bonus) Abstract Base Classes: (<i>ABC<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-89b8694 elementor-widget elementor-widget-text-editor\" data-id=\"89b8694\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Abstract Classes are nice alternatives to concrete classes since they conveniently allow multiple inheritence.<\/p><p>They work well with unfinished, concept-like classes hence the name abstract. Abstract classes become functional with methods written in subclasses. When a developer is working with subclasses of an abstract class they know that the class is either incomplete or empty so this gives an opportunity to work with incomplete classes in a structured way. @abstractmethod is a useful decorator for abstract base classes in Python.<\/p><p>Here is an example with an <code>@abstractmethod<\/code>\u00a0:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0ff5d9c elementor-widget elementor-widget-html\" data-id=\"0ff5d9c\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from abc import ABC, abstractmethod\n \nclass ClassAbstract(ABC):\n \n    def __init__(self, val1):\n        self.value1 = val1\n    \n    @abstractmethod\n    def under_construction(self):\n        pass\n\nclass DDD(ClassAbstract):\n\n    def under_construction(self):\n        return self.value1\n    \ndata1 = DDD(10)\n\nprint(data1.under_construction())\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-dea8fbb elementor-widget elementor-widget-text-editor\" data-id=\"dea8fbb\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>10<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-aca5f2e elementor-widget elementor-widget-text-editor\" data-id=\"aca5f2e\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>While the example demonstrates abstract classes perfectly here are 2 &#8220;bad&#8221; examples to further elaborate abstract classes:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f599b23 elementor-widget elementor-widget-html\" data-id=\"f599b23\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from abc import ABC, abstractmethod\n \nclass ClassAbstract(ABC):\n \n    def __init__(self, val1):\n        self.value1 = val1\n    \n    @abstractmethod\n    def under_construction(self):\n        pass\n\nclass DDD(ClassAbstract):\n\n    def multiplier(self):\n        return self.value1*10\n    \ndata1 = DDD(10)\n\nprint(data1.multiplier())\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b6b28ff elementor-widget elementor-widget-text-editor\" data-id=\"b6b28ff\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>TypeError: Can't instantiate abstract class DDD with abstract methods under_construction<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-98799c8 elementor-widget elementor-widget-text-editor\" data-id=\"98799c8\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You get the above error because you didn&#8217;t modify and complete the incomplete <strong>abstractmethod\u00a0<\/strong>inherited from the <b style=\"font-weight: bold;\">abstractclass.<\/b><\/p><p>Let&#8217;s look at another troubled example:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d3fb943 elementor-widget elementor-widget-text-editor\" data-id=\"d3fb943\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this example, <b>abstractmethod<\/b> is not enforced. This is only good old inheritence and not an <b>abstractclass. <\/b>It still works even though under_construction method is left untouched.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-feed4f8 elementor-widget elementor-widget-html\" data-id=\"feed4f8\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>from abc import ABC, abstractmethod\n \nclass ClassAbstract:\n \n    def __init__(self, val1):\n        self.value1 = val1\n    \n    def under_construction(self):\n        pass\n\nclass DDD(ClassAbstract):\n\n    def multiplier(self):\n        return self.value1*10\n    \ndata1 = DDD(10)\n\nprint(data1.multiplier())\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-117ef05 elementor-widget elementor-widget-text-editor\" data-id=\"117ef05\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<pre>100<\/pre>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4dd3cb5 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"4dd3cb5\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Bonus) c classes: (<i>cPickle, uJson and others<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9486065 elementor-widget elementor-widget-text-editor\" data-id=\"9486065\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>If you are serious about execution speed then you should definitely consider mingling with C and C++ in relation with Python.<\/p><p>With the help of C extensions some Python operations can be sped up to 100x, 500x or 1000x.<\/p><p>The details of these concepts is beyond the scope of this Python tutorial but if you&#8217;re interested you should definitely check out Cython, distutils and setuptools.<\/p><p>Distutils and setuptools make it possible to write extension modules for Python written in either C or Python or even a mix code.<\/p><p>Cython is a Python-like languages that compiles like C catching up with C speeds in many cases.<\/p><p>CPython, often confused with Cython is a Python implementation in C and it requires writing C code for the most part but both will allow you to write libraries in C that can be implemented in Python such as Python&#8217;s standard library <b>numpy.<\/b><\/p><p>You can also check out alternative libraries that are already written in C by the community. One example to that is <b>uJSON<\/b>, an ultra-fast alternative to Python&#8217;s standard JSON library, or <b>cPickle<\/b> as an alternative to <b>Pickle.<\/b><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Python Tips &amp; Tricks (Part III) Advanced Level HolyPython.com Here are more Python tips about relatively more complex Python concepts. 71) Annotated Assignment Statement: (:) This might not seem as impressive as some other tricks but it&#8217;s a new syntax that was introduced to Python in recent years and just good to be aware of. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10896,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[35,52],"tags":[],"class_list":["post-29839","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-advanced","category-tutorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts\/29839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/comments?post=29839"}],"version-history":[{"count":0,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts\/29839\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media\/10896"}],"wp:attachment":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media?parent=29839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/categories?post=29839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/tags?post=29839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}