Posts

[Python] Understanding the sorted() Function in Python — Guide and Examples

Hello, this is BlockDMask. Today we’ll explore Python’s built-in sorted() function, which lets you sort any iterable and return a new list. If you’re looking for the list.sort() method instead, check out [this post on list.sort()] . <Table of Contents> What is sorted()? Example 1: Sorting a List of Numbers Example 2: Sorting Strings Case-Insensitive Example 3: Sorting Tuples by Second Element Example 4: Sorting Dictionary Keys and Items Example 5: Sorting Dictionary by Value Bonus Tip: Sorting Custom Objects 1. What is sorted()? The sorted() function takes any iterable—like a list, tuple, string, or dict—and returns a new, sorted list : sorted(iterable) sorted(iterable, reverse=True) sorted(iterable, key=func) sorted(iterable, key=func, reverse=True) iterable : any object you can loop over (list, tuple, string, dict). key : a function that extracts a comparison key from each element. reverse : False for ascending (default), True ...

[Python] 3 Ways to Limit Decimal Places in Python (With Examples)

Hello, this is BlockDMask. In this post, we'll explore how to control the number of decimal places in Python. Whether you're formatting prices, displaying percentages, or rounding calculations — precision matters. <Table of Contents> Using the round() function Using the format() function Using f-strings 💡Bonus Tip: Using decimal for accurate rounding 1. Using the round() Function The round() function is the most basic way to round a number to a certain number of decimal places. It takes two arguments: the number to round, and the number of decimal places. price1 = round(19.8765) # 20 price2 = round(19.8765, 0) # 20.0 price3 = round(19.8765, 1) # 19.9 price4 = round(19.8765, 2) # 19.88 price5 = round(19.8765, 3) # 19.877 print(f"Rounded (no decimal): {price1}") print(f"Rounded (0 decimals): {price2}") print(f"Rounded (1 decimal): {price3}") print(f"Rounded (2 decimal...

[Python] How to Use the sort() Function in Python with Examples

Hello, this is BlockDMask. Today, we’ll take a deep look at how to use the sort() method in Python to sort a list. We’ll cover ascending and descending sorting, and clarify the difference between sort() and sorted() . <Table of Contents> How the sort() method works in Python Ascending and descending sort with reverse parameter Difference between sort() and sorted() 1. How the sort() method works in Python 1-1) Basic usage of sort() The list.sort() method directly modifies the original list in place. It does not return a new list. This method is only available for list objects. Note: If you want to sort something without changing the original list, use sorted() instead. We'll cover that later. 1-2) sort() examples with numbers and strings # Sorting numbers temperatures = [86, 74, 90, 61, 79, 68] print("1. Sorted temperatures:") temperatures.sort() print(temperatures) # Sorting strings (lowercase only) cities = ['chicago', ...

C memcpy() Function Explained with Examples (Beginner Friendly)

Hello, this is BlockDMask. Today, we will learn how to use the memcpy() function in C/C++ to copy memory contents from one place to another. Now, let’s dive into how memcpy() works, with practical examples and some important things to watch out for. Table of Contents 1. What is memcpy()? 2. memcpy example with int array 3. memcpy example with partial string copy 4. memcpy example with full string copy (critical point) 5. Extra example: memcpy with structure ✅ 1. What is memcpy()? The function name memcpy comes from "memory copy". As the name suggests, it copies a block of memory from a source to a destination in raw bytes. Header files: In C: <string.h> In C++: <cstring> Function prototype: void* memcpy(void* dest, const void* source, size_t num); Parameters: dest : Pointer to the destination memory block source : Pointer to the source memory block num : Number of bytes to copy In short, memcpy(dest, sou...

How to View Saved Wi-Fi Password on Windows (Step-by-Step Guide)

Hello, this is BlockDMask. Today, we’ll learn how to recover the Wi-Fi password for networks you've previously connected to in Windows . Have you ever needed to connect a phone, tablet, or new laptop to your Wi-Fi, but couldn’t recall the password? If your computer has connected to the network before, Windows may have saved the password — and you can retrieve it easily! Let’s go through two simple ways to find your Wi-Fi password. Table of Contents 1. Retrieve Wi-Fi password using Command Prompt 2. Retrieve Wi-Fi password using Control Panel 3. How to change your Wi-Fi password ✅ Method 1: Retrieve Wi-Fi password using Command Prompt Press Windows Key + R to open the Run dialog. Type cmd and press Enter to open Command Prompt. In the command window, type the following command: netsh wlan show profiles This command lists all wireless networks your computer has connected to before. Find the profile name (SSID) of the network you want to che...

How to Check Your IP Address in Windows (Private IP & Public IP explained)

Hello, this is BlockDMask. Today, we'll learn how to check your computer's IP address in Windows — both your private (internal) IP and public (external) IP. If you’ve ever worked with remote access, routers, VPNs, or server setups, you’ve probably heard of "IP addresses." Fortunately, checking your IP is very easy, and it's useful in many situations. Table of Contents 1. How to check your Private IP (Internal IP) 2. How to check your Public IP (External IP) 3. Why do you need to check your IP address? ✅ How to check your Private IP address (inside your local network) This is the IP address assigned to your computer by your router, usually in a home or office network. Other devices on the same Wi-Fi network have similar addresses. 📌 Method 1: Using Command Prompt (cmd) Press Windows Key + R to open the Run window. Type cmd and press Enter. In the black command window, type: ipconfig You’ll see detailed network informat...

Python isdigit() Explained: Check if a String Contains Only Digits (with examples)

Hello, this is BlockDMask. Today, we will explore how to check whether a string contains only digits in Python using the isdigit() method. This is very useful when you're validating user input, processing files, or scraping web data where numeric checks are needed. Table of Contents 1. What is isdigit() in Python? 2. Limitations and common pitfalls of isdigit() 3. Practical examples of isdigit() 4. Difference between isdigit(), isdecimal(), and isnumeric() 1. What is isdigit() in Python? The isdigit() method checks if a string contains only numeric digits (0–9). It belongs to the string class and can be used like this: str.isdigit() Basic behavior: Returns True if all characters are digits (0-9) Returns False if any non-digit character exists Signs like - (negative) or . (decimal) make it return False Certain Unicode numeric characters may return True (e.g. superscripts, fractions) Typically used for checking whether user inpu...