Python | Split String after Character

Problem Formulation πŸ“œ Problem: Given a string. How will you split the string after a specific character? Note that there can be different scenarios that can come up when you are trying to split a string after a certain character/sub-string. So, let’s understand the given problem with the help of numerous examples. 🏷️Scenario 1: Splitting … Read more

The Fasting Cure [Book Summary + Free Download]

Fasting has many scientifically proven benefits for your body and overall health: Intermittent fasting improved blood pressure and resting heart rates as well as other heart-related measurements. Physical performance. Young men who fasted for 16 hours showed fat loss while maintaining muscle mass. Mice who were fed on alternate days showed better endurance in running. … Read more

How to Add Elements to a Python Set

Problem Formulation and Solution Overview This article will show you how to add elements to a Python set. ℹ️ Info: A Python set is a collection of unique item(s) saved in no particular order (unordered). A set cannot be changed. However, elements can be added and removed. Sets can also perform calculations like union, intersection, … Read more

How to Remove ‘\x’ From a Hex String in Python?

Problem Formulation + Examples πŸ’¬ Question: Given a string of hexadecimal encoded string such as ‘\x00\xff\xf2’. How to remove the ‘\x’ prefixes or characters from the hex string? Here are a few examples of what you want to accomplish: Hex String Desired Output ‘\x00\xff\xf2′ ’00fff2’ ‘\x41\x42\x43’ ‘414243’ ‘\x53′ ’53’ ‘\xff\xff\xff\xff\xff’ ‘ffffffffff’ ‘\x00\x6a\x6f’ ‘006a6f’ Strawman Solutions … Read more

Python Create JSON File

Problem Formulation and Solution Overview This article focuses on working with a JSON file. JSON is an acronym for JavaScript Object Notation. This is a flat-text file formatted based on JavaScript (JS) Syntax. This file is most commonly noted for its ability to transmit data to/from web applications, such as sending/receiving data from a Server/Client … Read more

Python Hex to Float Conversion

Problem Formulation πŸ’¬ Question: Given a hexadecimal string. How to convert it to a float? Examples Here are a few example conversions where each hex string represents four bytes, i.e., two hex characters per byte. Hex String Float ‘0f0f0f0f’ 7.053344520075142e-30 ‘4282cbf1’ 65.39832305908203 ‘43322ffb’ 178.1874237060547 ‘534f11ab’ 889354649600.0 Solution – Convert Hex to Float The expression struct.unpack(‘!f’, … Read more

How to Open a URL in Your Browser From a Python Script?

To open a URL in your standard browser (Win, macOS, Linux) from your Python script, e.g., call webbrowser.open(‘https://google.com’) to open Google. Don’t forget to run import webbrowser first. But you don’t have to install the module because it’s already in Python’s standard library. Example Here’s an example Python script that opens the URL ‘https://finxter.com’: A … Read more

Python Hex String to Little Endian (Bytes/Integer)

What Is Big/Little Endian? Computers perform computations on data that is represented with bytes, i.e., sequences of 0s and 1s. A computer program manipulates data by loading data from memory (RAM, Cache, Disk, SSD), performing computations based on that data, and storing the resulting data back into the memory. A computer program loads and stores … Read more

Python Hex String to Decimal

Question πŸ’¬ How to convert a hexadecimal string to a decimal integer value in Python? Answer Summary To convert a hex string to a decimal integer value, pass the hex string into the int() function with base argument such as int(‘0xfff’, base=16), or eval() function such as eval(‘0xfff’). The result is a decimal integer value … Read more