This Week I Learned: 2022W41

Mon Oct 17 2022

Sorting - PHP - Python

In Python, as well as in PHP, by default, sorting is done respecting ASCII order and not alphabetical order.

So in Python:

my_list = ['z', 'A', 'a', 'Z']

my_list # ['A', 'Z', 'a', 'z']

And in PHP:

$myList = ['z', 'A', 'a', 'Z'];

$myList; // ['A', 'Z', 'a', 'z']

Discovered this in Beyond the Basic Stuff with Python from Al Sweigart.

Python - Multiple equality

In Python we can use a == b == c. It works. But we shouldn’t use a != b != c.


Because a == b == c is actually transformed into a == b and b == c. Which in the case of equality works the same. But with a != b != c it’s transformed into a != b and b != c. Which is not the same.

Indeed, if a and c are the same, this is True: 'a' != 'b' != 'a'. If we change the order, it’s then False: 'a' != 'a' != 'b'.

Also found in Al Sweigart’s book.

PHP - Terminal - Tailwind

Termwind is a PHP library allowing to use Tailwind CSS ’ syntax to build TUI applications. Not tested yet, but looks interesting.

Build you own thing

A Github repository called build-your-own-x provides a list of technologies (bots, databases, docker…) rebuilt from scratch in several languages. Quite an interesting list.

Rust - Memory

Rust has the concept of ownership and borrowing. Never read something like this elsewhere before. Sounds really interesting (and confusing for now to me).