AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 167 of 840

Essential Python Tips And Tricks For Programmers?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 325 Views

Python offers numerous shortcuts and tricks that can make your code more concise and efficient. These techniques are particularly useful in competitive programming and professional development where clean, optimized code matters. Finding Largest and Smallest Elements with heapq Getting n Largest Elements The heapq module provides efficient functions to find the largest elements without sorting the entire list − import heapq marks = [91, 67, 34, 56, 78, 99, 87, 23, 78, 66] print("Marks =", marks) print("2 Largest =", heapq.nlargest(2, marks)) Marks = [91, 67, 34, 56, 78, 99, 87, 23, ...

Read More

Python program to check if a number is Prime or not

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 218K+ Views

A prime number is a natural number greater than 1 that has exactly two factors: 1 and itself. Numbers like 2, 3, 5, 7, 11 are prime numbers because they cannot be divided evenly by any other number except 1 and themselves. Let's say the following is our input − 7 The output should be as follows − Prime Number Using Basic Loop Method Let us check if a number is prime using a for loop by testing divisibility from 2 to half of the number − Example ...

Read More

Python program to print duplicates from a list of integers?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 3K+ Views

A duplicate element in a list is an item that appears more than once. Python provides several efficient methods to identify and extract duplicate elements from a list of integers. Let's say we have the following input list − [5, 10, 15, 10, 20, 25, 30, 20, 40] The output should display duplicate elements − [10, 20] Using For Loop with Dictionary This approach uses a dictionary to count occurrences and a nested condition to track duplicates − # Create a List numbers = [5, 10, 15, 18, ...

Read More

Quickly convert Decimal to other bases in Python

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 2K+ Views

To quickly convert decimal numbers to other bases, Python provides built-in functions that make the process simple and efficient − Decimal to Binary − bin() Decimal to Octal − oct() Decimal to Hexadecimal − hex() The decimal number system has base 10 and uses digits 0-9. Binary (base 2) uses only 0 and 1. Octal (base 8) uses digits 0-7. Hexadecimal (base 16) uses digits 0-9 and letters A-F (where A=10, B=11, C=12, D=13, E=14, F=15). Convert Decimal to Binary The bin() function converts a decimal number to its binary representation ? ...

Read More

Python Helpers for Computing Deltas

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 325 Views

The difflib module in Python provides tools for computing deltas between sequences. It's particularly useful for comparing files and generating difference reports in various formats including HTML, context, and unified diffs. import difflib SequenceMatcher Class The difflib.SequenceMatcher class compares two sequences of any type and provides detailed comparison methods ? Key Methods set_seqs(a, b) − Set both sequences to compare. Computes and caches detailed information about the second sequence. set_seq1(a) − Set the first sequence to compare. set_seq2(b) − Set the second sequence to compare. find_longest_match(alo, ahi, blo, bhi) − Find the ...

Read More

Python program to sort a list according to the second element in the sublist.

AmitDiwan
AmitDiwan
Updated on 24-Mar-2026 2K+ Views

In this article, we will learn how to sort a list according to the second element in each sublist. This is useful when working with data where each item is a pair, such as name-score pairs or key-value combinations. Let's say we have the following list ? [['jack', 50], ['antony', 20], ['jones', 87], ['gary', 70], ['tom', 90], ['sam', 110], ['warner', 65]] The output should be sorted according to the second element ? [['antony', 20], ['jack', 50], ['warner', 65], ['gary', 70], ['jones', 87], ['tom', 90], ['sam', 110]] Using sort() Method The ...

Read More

Difference Between RPC and RMI

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 4K+ Views

In distributed systems, RPC (Remote Procedure Call) and RMI (Remote Method Invocation) are two fundamental communication mechanisms that enable processes on different machines to interact seamlessly. While both facilitate remote communication, they differ significantly in their design philosophy, implementation approach, and use cases. RPC (Remote Procedure Call) Remote Procedure Call (RPC) is a protocol that allows a program to execute procedures or functions on a remote machine as if they were local calls. It abstracts the network communication details, making distributed programming more straightforward. Key Characteristics of RPC It is implemented as a library or ...

Read More

Difference Between Microkernel and Monolithic Kernel

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 2K+ Views

In this post, we will understand the difference between microkernel and monolithic kernel − two fundamental approaches to operating system kernel design that differ in how they organize system services and manage resources. Kernel Architecture Comparison Microkernel User Space File System Device Driver Network ...

Read More

Difference Between fork() and vfork()

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

In this post, we will understand the difference between system calls fork() and vfork() − Both fork() and vfork() are system calls used to create child processes in Unix-like operating systems. However, they differ significantly in how they handle memory management, execution order, and resource sharing between parent and child processes. The fork() System Call The fork() system call creates a new process by making a complete copy of the parent process. Here are its key characteristics: The child and parent process have separate memory spaces. The child and parent process are executed simultaneously. This ...

Read More

SByte.GetTypeCode Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 141 Views

The SByte.GetTypeCode() method in C# is used to return the TypeCode enumeration value for the sbyte data type. This method is part of the IConvertible interface and helps identify the specific type of a value at runtime. Syntax Following is the syntax for the SByte.GetTypeCode() method − public TypeCode GetTypeCode(); Return Value The method returns TypeCode.SByte, which is the enumeration constant representing the sbyte type. Using GetTypeCode() with SByte Values Example using System; public class Demo { public static void Main() { ...

Read More
Showing 1661–1670 of 8,392 articles
« Prev 1 165 166 167 168 169 840 Next »
Advertisements