Pinned Tweet
The new pattern matching support in #python 3.10 is so useful -- and powerful -- that it needs to be seen to be believed. It will replace large swathes of tedious if-statements if you are willing to give it a try!
inspiredpython.com/course/pa…
Have you played #Wordle yet? It's a challenging puzzle game where you have to guess a five-letter word. Here's how you can use #Python to generate an efficient strategy to guess the word for you.
inspiredpython.com/article/s…
In part 3 of Let's Write a Game Boy Emulator in #Python our attention turns to designing the CPU.
🐍 Love Python? Follow @InspiredPython
inspiredpython.com/course/ga…
Well done, Bob. Congratulations.
Celebrating 5 years of PyBites 🍰 🎉
Awesome work @juliansequeira 🍻, could not have done it without you and our amazing community 🙏
Very excited for what the next 5 years will bring ... 🔥
1
1
Pytest fixtures makes it a breeze to initialize test data and manage your test harnesses effectively.
Here's five advanced #python pytest fixture patterns that'll supercharge your testing:
🐍 Follow @InspiredPython for more Python
🔗 inspiredpython.com/article/f…
In part 2 of our series on Let's Write a Game Boy Emulator in #Python, we look at the instruction decoder and disassembler, and how to read the cartridge header metadata.
inspiredpython.com/course/ga…
Have you ever heard of the Hypothesis #python package? It uses clever algorithms to find test cases that break your code. It works with unittest and pytest.
Here's how:
inspiredpython.com/course/te…
It's the bitwise complement of a number which has unintended consequences when used incorrectly. I would argue you should never use this unless you really do want the complementary number:
>>> ~0
-1
>>> l = [1,2,3]
>>> l[-0]
1
>>> l[~0]
3
🐍Python Tip of the day:
You can use `~i` to index a list in python from behind, instead of `-1 - i`:
1
3
#Python strings can map one character to another using a translation table of character mappings. You can use it to great effect to, for example, generate unicode text using ASCII as the input.
Here's how you can flatten deeply-nested lists, tuples and sets in #Python 3.10 using structural pattern matching. It's smart enough to skip dicts and strings, and it's easy to extend to suit your needs.
Manipulating file and path strings is dreary work if you have to split, extract, and join strings to get what you want. But the new pattern matching feature in #Python offers immediate reprieve.
inspiredpython.com/course/pa…
Remember the Game Boy? Have you ever wondered what it would take to build an emulator capable of running Game Boy cartridges? Let’s write a #Python #gameboy #emulator and find out!
inspiredpython.com/course/ga…
You can use the pop(key) method to remove (and return) the value of an item in a dictionary. It is very useful if you want to destructively retrieve an item from a dictionary and remove it at the same time. You can also use popitem() to get the key and value.
There are multiple ways of merging dictionaries to create a new one, but Python 3.9 introduces a much easier notation. All methods merge left-to-right, with dictionaries to the right overriding items to the left, with the exception of ChainMap where it is the other way around.
Because keys must be hashable and unique in a dictionary, they act like sets. You can use most set-like operations on them, and because they’re views, they always reflect the actual contents of the underlying dictionary. Don't forget that views are read only!
When you get the keys(), values() or items() from a #python dictionary, you are given a view of the elements in the dictionary. If you modify the dictionary the reference you have is updated to reflect this.
Watch out if you use assertions and Exceptions interchangeably. The assert statement is there to check for system invariants and not for validating your business logic. Assertion checks are disabled if you enable the optimizer in #Python — so watch out!
Recursively listing files and directories – with wildcards – is trivial with the pathlib Path class and much easier than using scandir() in the os module. The rglob method returns a generator so you can consume a single match at a time.





















