[🐍PyTricks]: You can use "json.dumps()" to pretty-print Python dicts

# The standard string repr for dicts is hard to read:
>>> my_mapping = {'a': 23, 'b': 42, 'c': 0xc0ffee}
>>> my_mapping
{'b': 42, 'c': 12648430. 'a': 23}  # 😞

# The "json" module can do a much better job:
>>> import json
>>> print(json.dumps(my_mapping, indent=4, sort_keys=True))
{
    "a": 23,
    "b": 42,
    "c": 12648430
}

# Note this only works with dicts containing
# primitive types (check out the "pprint" module):
>>> json.dumps({all: 'yup'})
TypeError: keys must be a string

[🐍PyTricks]: Function argument unpacking in Python

# Why Python Is Great:
# Function argument unpacking

def myfunc(x, y, z):
    print(x, y, z)

tuple_vec = (1, 0, 1)
dict_vec = {'x': 1, 'y': 0, 'z': 1}

>>> myfunc(*tuple_vec)
1, 0, 1

>>> myfunc(**dict_vec)
1, 0, 1

🐍PyTricks]: Merging two dicts in Python 3.5+ with a single expression

Source :

Dan at Real Python info@realpython.com


# How to merge two dictionaries
# in Python 3.5+

>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 3, 'c': 4}

>>> z = {**x, **y}

>>> z
{'c': 4, 'a': 1, 'b': 3}

# In Python 2.x you could
# use this:
>>> z = dict(x, **y)
>>> z
{'a': 1, 'c': 4, 'b': 3}

# In these examples, Python merges dictionary keys
# in the order listed in the expression, overwriting 
# duplicates from left to right.
#
# See: https://www.youtube.com/watch?v=Duexw08KaC8

🐍PyTricks]: Different ways to test multiple flags at once in Python

Dan at Real Python info@realpython.com

🐍PyTricks]: How to sort a Python dict by value

Dan at Real Python info@realpython.com

🐍PyTricks]: The get() method on Python dicts and its "default" arg

# The get() method on dicts
# and its "default" argument

name_for_userid = {
    382: "Alice",
    590: "Bob",
    951: "Dilbert",
}

def greeting(userid):
    return "Hi %s!" % name_for_userid.get(userid, "there")

>>> greeting(382)
"Hi Alice!"

>>> greeting(333333)
"Hi there!"



Source :

Dan at Real Python info@realpython.com

[🐍PyTricks]: Python's namedtuples can be a great alternative to defining a class manually

# Why Python is Great: Namedtuples
# Using namedtuple is way shorter than
# defining a class manually:
>>> from collections import namedtuple
>>> Car = namedtuple('Car', 'color mileage')

# Our new "Car" class works as expected:
>>> my_car = Car('red', 3812.4)
>>> my_car.color
'red'
>>> my_car.mileage
3812.4

# We get a nice string repr for free:
>>> my_car
Car(color='red' , mileage=3812.4)

# Like tuples, namedtuples are immutable:
>>> my_car.color = 'blue'
AttributeError: "can't set attribute"


Dan at Real Python info@realpython.com

🐍PyTricks]: Try running "import this" inside a Python REPL ...

Source :

Dan at Real Python info@realpython.com

Python Weekly Issue 430

Source: rahul@pythonweekly.com

Python Weekly

Welcome to issue 430 of Python Weekly. I wish you all Happy New Year and I am excited to continue sending you the best Python related links in 2020.
From Our Sponsor 
 
Python developers are in demand on Vettery
Vettery is an online hiring marketplace that's changing the way people hire and get hired. Ready for a bold career move? Make a free profile, name your salary, and connect with hiring managers from top employers today.

Articles, Tutorials and Talks

Making Python Programs Blazingly Fast
Python haters always say, that one of reasons they don't want to use it, is that it's slow. Well, whether specific program - regardless of programming language used - is fast or slow is very much dependant on developer who wrote it and their skill and ability to write optimized and fast programs. So, let's prove some people wrong and let's see how we can improve performance of our Python programs and make them really fast!

Numba makes Python 1000x faster! 
In this video I introduce the absolute minimum you need to know about Numba which is a just in time compiler for a subset of Python and Numpy. The first half of the video is dedicated to a basic intro and to highlighting a number of very common mistakes people make when using Numba. The remaining video presents a real world-ish simulation problem, shows up to a 1000x acceleration with Numba in both single and multithreaded cases, and concludes with a "reading list" for learning more about Numba.

How to use Flask with gevent (uWSGI and Gunicorn editions)
Create asynchronous Flask application and run it with uWSGI or Gunicorn behind Nginx reverse proxy.

Introduction to ASGI: Emergence of an Async Python Web Ecosystem
There's a lot of exciting stuff happening in the Python web development ecosystem right now — one of the main drivers of this endeavour is ASGI, the Asynchronous Standard Gateway Interface. This post is targeted at people interested in recent trends of Python web development. It takes you on a guided tour about what ASGI is and what it means for modern Python web development.

Develop an Intuition for Severely Skewed Class Distributions
An imbalanced classification problem is a problem that involves predicting a class label where the distribution of class labels in the training dataset is not equal. Differences in the class distribution for an imbalanced classification problem will influence the choice of data preparation and modeling algorithms. Therefore it is critical that practitioners develop an intuition for the implications for different class distributions. In this tutorial, you will discover how to develop a practical intuition for imbalanced and highly skewed class distributions.

Robot development with Jupyter
This post shows the available tools in the Jupyter ecosystem to build advanced visualizations in Jupyter Notebooks and standalone web apps using Voilá, and how to deploy those apps to the robotics cloud.

Creating a Moon Animation Using NASA Images and Python
Here’s how we can create a video of the moon in just a few lines of python code!

Automating an Insider Selling Dashboard with Python & Tableau | Part 2: Collecting Live Stock Data 
In this part, we're using pandas datareader to collect real-time stock data for our insider trades dashboard. There are lots of good nuggets in here like using Pandas to calculate moving averages and to read html.

Python Dictionaries 101: A Detailed Visual Introduction

I'm not feeling the async pressure

Word raking with tf-idf and Python

Label smoothing with Keras, TensorFlow, and Deep Learning

Meditations on the Zen of Python

How to use Pandas get_dummies to Create Dummy Variables in Python


Interesting Projects, Tools and Libraries

Typer
Typer, build great CLIs. Easy to code. Based on Python type hints.

AI_Sudoku
GUI based Smart Sudoku Solver that tries to extract a sudoku puzzle from a photo and solve it.

klaxon
Mac OS notifications from Python.

django-simple-task
Simple background task for Django 3.

ffmpeg-python
Python bindings for FFmpeg - with complex filtering support.

Traffic-Signal-Violation-Detection-System
A Computer Vision based Traffic Signal Violation Detection System from video footage using YOLOv3 & Tkinter. (GUI Included)

pylightxl
A light weight, zero dependency, minial functionality excel read/writer python library.

XSS-Finder
Heavy-duty and Advanced Cross Site Scripting Scanner.

Robatim
Robatim is a pseudo-random music generator based on the conventions of the common practice period.


Upcoming Events and Webinars

Austin Python Meetup January 2020 - Austin, TX
Jupyter notebooks are excellent for exploration, particularly for analytics and visualization. However, when it comes to developing a library or self-contained code, we can find ourselves copying and pasting to our favorite text editor or IDE. In this presentation Leanne Fitzpatrick  will present nbdev, an elegant solution to this problem developed by fast.ai.

CI/CD for Python on AWS - Glen Allen, VA
We are going to be demonstrating 1) how to setup a Continuous Integration pipeline for a Python application and 2) how to implement Continuous Deployment using Python/Boto3 on AWS.

PyMNtos Python Presentation Night #80 - Minneapolis, MN

San Francisco Python Meetup January 2020 - San Francisco, CA

PyAtl Meetup January 2020 - Atlanta, GA
 
Our Other Newsletters
NoSQL Weekly - A free weekly newsletter featuring the best hand curated news, articles, tools and libraries, new releases, jobs etc related to NoSQL.

Founder Weekly - A free weekly newsletter for entrepreneurs featuring best curated content, must read articles, how to guides, tips and tricks, resources, events and more.
 

Python Weekly Issue 429

View this email in your browser
Source : 

Python Weekly rahul@pythonweekly.com

Python Weekly

Welcome to issue 429 of Python Weekly. Let's get straight to the links this week.
 Learn Python & Ethical Hacking From Scratch
Start from 0 & learn both topics simultaneously from scratch by writing 20+ hacking programs

Articles, Tutorials and Talks

Setting up a Raspberry Pi 4 as a development machine for your iPad Pro
A pretty cool post that shows you how you can use iPad Pro for software development using the Raspberry Pi 4 as a USB device.

Deepfake Bot Submissions to Federal Public Comment Websites Cannot Be Distinguished from Human Submissions
Federal public comment websites currently are unable to detect Deepfake Text once submitted. A Harvard undergrad created a computer program (a bot) that generated and submitted 1,001 deepfake comments regarding a Medicaid reform waiver to a federal public comment website, stopping submission when these comments comprised more than half of all submitted comments. He then formally withdrew the bot comments.

Porting Flask to FastAPI for ML Model Serving
Due to its simplicity, Flask is a very popular web framework for building REST APIs in Python - particularly for serving Machine Learning models. In this post we'll learn how to migrate to the newer FastAPI framework to take advantage of advances in type checking and asynchronous programming.

24 Evaluation Metrics for Binary Classification (And When to Use Them)
Not sure which evaluation metric you should choose for your binary classification problem? After reading this post you should have a good idea. You will learn about a bunch of common and lesser-known evaluation metrics and charts to understand how to choose the model performance metric for your problem.

Creating an Animated Christmas Tree in your Terminal with Python 
Did a little Christmas special programming project by making an animated Christmas Tree that runs in your terminal. Sometimes programming can be fun, this is one of those times.

Fullstack NLP: Building & Deploying End-to-end Fake News Classifier
This is a tutorial on building the API+UI of NLP text classification web application and deploying it to production.

12 Trending Alternatives for Distributing Python Applications in 2020
Whether delivering an executable, a virtual environment, your packaged code, or a full application, this list includes both standard systems and some up-and-comers to keep in mind as we enter 2020.

The Video Search Engine — My Journey Into Computer Vision
Creating video is easy, but who’s got time to watch it all? I propose a video search engine to find relevant moments (prototype included).

Creating Interactive Dashboards from Jupyter Notebooks
This article discusses how to build an interactive dashboard to analyze reddit content and display interactive graphs of the result using Voilà.

Dependency Injection in Python with Pinject
In this post, you will learn the basic principles of Dependency Injection and how to implement it in Python using the Pinject library.

Automating an Insider Selling Dashboard with Python and Tableau | Part 1: Web Scraping with Selenium 

5 Simple Tips for More Secure Python

Flight stats, entertainment, and trying to crack Widevine

Using Python and OCaml in the same Jupyter notebook

Working with Redis in Python with Django


Interesting Projects, Tools and Libraries

labelme
Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).

Checkov
Checkov is a static code analysis tool for infrastructure-as-code. It scans cloud infrastructure provisioned using Terraform and detects security and compliance misconfigurations.

NewsPie
A minimalistic news aggregator built with Flask and powered by News API.

aws-data-wrangler
Utility belt to handle data on AWS.

SpectroGraphic
Turn an image into sound whose spectrogram looks like the image.

pix-to-xls
A simple tool to make ascii art from an image using excel colored cells.

SharedVault
SharedVault is a small application that allows you to define a secret that will require multiple people to unlock.

ArcaneVM
A Fully Homomorphic Encryption Brainf**k virtual machine.

Silver
masscan is fast, nmap can fingerprint software and vulners is a huge vulnerability database. Silver is a front-end that allows complete utilization of these programs by parsing data, spawning parallel processes, caching vulnerability data for faster scanning over time and much more.

New Releases

Python 3.8.1, 3.7.6, 3.6.10, and 3.9.0a2

PyPy 7.3.0 released