Have you ever wondered if it’s possible to automatically back up Windows files to iCloud, including a system image? It definitely is and here is how.

Accessing Windows File History and system images from iPhone

Many people out there own Apple products like an iPhone or a MacBook, with an iCloud account. Some, even pay for a storage plan that gives a lot of storage available for photos, videos, documents, etc.

Some of those, also make use of Windows machines for working and even for other side projects. …

So, you are getting good at Python dictionaries, but you must keep stepping up the ladder.

Copying each key and value to another dictionary

Traditional way:

a = {'hey': 1, 'ho': 2, "let's": 3, 'go': 4}
b = {}
for k, v in a.items():
b[k] = v
>>> {'hey': 1, 'ho': 2, "let's": 3, 'go': 4}

Using Dictionary Comprehensions:

a = {'hey': 1, 'ho': 2, "let's": 3, 'go': 4}
b = {k: v for k, v in a.items()}
>>> {'hey': 1, 'ho': 2, "let's": 3, 'go': 4}

Copying each key and value to another dictionary if a certain condition is met

Traditional way:

a = {'hey': 1, 'ho': 2, "let's": 3, 'go': 4}
b = {}
for k, v in a.items():
if v > 1:
b[k] = v
>>> {'ho': 2, "let's": 3, 'go': 4}

Many Python programmers depend on printing out statements on console, as a GUI isn’t always necessary. The issue sometimes is that a black and white console doesn’t help much when one has several console windows opened and running different functions. For example:

Honestly, you are not going to see what’s wrong (or right) easily when everything is just white on a black background.

So here it comes a library to help us out, fortunately! It’s called Termcolor. So let’s install it via python -m pip install termcolor command.

How to use it

It’s pretty simple. As simples as Python.

from termcolor import coloredprint(colored('Hello'…

Getting straight to the point, this is a list of features many Python programmers don’t know exist.

1- Merging dictionaries:

d1 = {'a':1, 'b':2}
d2 = {'c':3, 'd':4, 'e':'5'}
d3 = {**d1, **d2}
>>> {'y': 10, 'c': 3, 'd': 4, 'e': '5'}

2- Merging dictionaries in Python 3.9:

d1 = {'a':1, 'b':2}
d2 = {'c':3, 'd':4, 'e':'5'}
d3 = d1 | d2
>>> {'y': 10, 'c': 3, 'd': 4, 'e': '5'}

3- Naturally printing:

a = "John"
b = 5
c = f"{a} has {b} eggs."
>>> John has 5 eggs.

4- Floor division:

x = 15 // 2
>>> 7

5- List slicing & negative index:

a = [1,2,3,4,5,7]
b = a[3:-1]
>>> [4, 5]

6- Summing the values of each key in a dictionary:

According to Ronald Graham, Recursion is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem.

Image from: xkcd

Differently from what usually people say about Recursion, I would say it’s not that difficult if you start it simple.

What makes a function or method recursive?

  • Must always have a base case;
  • Must call itself;
  • Must solve smaller instances of problem in order to solve the problem completely;

What is a base case?

A base case is an exit strategy. It tells your function when it should stop calling itself.

How a function calls itself?

A function calls itself by returning itself, instead of returning a value.

How to solve smaller instances of a problem?

You can solve smaller…

In my previous article, I showed in a simple and practical way, how to run a for loop function 3x simultaneously, supposing you have at least 3 processor’s cores available.

So, if you haven’t yet, I strongly suggest you to take a look (and practice) on it before landing on this. Click here.

Multiprocessing alone is not enough

So, why should one say Multiprocessing isn’t enough? Short answer: because it’s True. Not so short answer: because you might end up not making use of all cores available, at the same time you keep waiting for the process to finish in each of the cores running…

Photo by Chris Ried on Unsplash

One of the hardest things a developer might face is to make his or her code run fast(er). The issue is that many tasks take time to be processed, even on fast computers with several cores.

Partially it happens because of Python GIL (Python Global Interpreter Lock) that allows only one Thread to take control over Python Interpreter, so you end up never using the whole power of the machine by just executing a function or method.

But don’t worry! You can take care of it.

Imagine you have to run a function 3x and each returned result composes a…

Uma das grandes dificuldades de todo desenvolvedor é fazer com que seu código seja rápido. O problema é que muitas tarefas levam tempo para serem processadas, mesmo em computadores rápidos e com muitos núcleos.

Em partes, isso se deve ao GIL (Python Global Interpreter Lock) que permite que apenas uma Thread tome controle do interpretador Python.

Mas é possível driblar isso. Então, mãos à massa!

Imagine que você precisa rodar 3 funções que compõe um resultado final. Aqui neste exemplo, vamos calcular a soma de n com todos os n anteriores. Faremos isso 3x e mediremos o tempo de processamento.

Julio Souto

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store