Articles on Trending Technologies

Technical articles with clear explanations and examples

Python – Remove characters greater than K

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 285 Views

When working with strings, you may need to filter out characters based on their position in the alphabet. This technique removes characters that appear after a certain position K in the alphabet using the ord() function to get Unicode values. Understanding the Approach The method compares each character's alphabetical position with K. Since lowercase 'a' has ASCII value 97, we subtract 97 from each character's ASCII value to get its alphabetical position (a=0, b=1, c=2, etc.). Example Here's how to remove characters greater than K from a list of strings ? words = ["python", ...

Read More

Python – Check if any list element is present in Tuple

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

When it is required to check if any list element is present in a tuple or not, Python provides several approaches. We can use simple iteration, the any() function, or set intersection for efficient checking. Using Simple Iteration This approach uses a loop to check each list element against the tuple ? my_tuple = (14, 35, 27, 99, 23, 89, 11) print("The tuple is :") print(my_tuple) my_list = [16, 27, 88, 99] print("The list is :") print(my_list) my_result = False for element in my_list: if element in my_tuple: ...

Read More

Python Program to sort rows of a matrix by custom element count

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 299 Views

When sorting rows of a matrix based on custom element count, we can define a helper function that counts how many elements from each row match our custom criteria. This approach uses list comprehension with the len() method to determine the sort order. Example Let's sort matrix rows by counting how many elements from each row appear in our custom list ? def get_count_matrix(my_key): return len([element for element in my_key if element in custom_list]) my_list = [[31, 5, 22, 7], [85, 5], [9, 11, 22], [7, 48]] print("The list is ...

Read More

Python Program to Filter Rows with a specific Pair Sum

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 332 Views

When working with lists of numbers, we often need to filter rows that contain a specific pair sum. This involves checking if any two elements in each row add up to a target value and keeping only those rows that satisfy this condition. Problem Overview Given a list of lists (rows) and a target sum, we want to filter and keep only the rows where at least one pair of elements adds up to the target value ? Method: Using Helper Function with List Comprehension We'll create a helper function to check for pair sums and ...

Read More

Program to check if number of compass usage to get out of a maze is enough in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 234 Views

In this problem, we need to determine if we can escape from a maze using a compass at most k times. The maze is represented as a matrix where 'S' is the starting position, 'D' is the destination (exit), '-' represents walkable paths, and 'O' represents blocked cells. The compass is used when we have multiple path choices at any position. Understanding the Problem The key insight is that we only need to use the compass when we have multiple valid moves from our current position. If there's only one valid path, we can move without using the ...

Read More

Program to find out the minimum number of moves for a chess piece to reach every position in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 787 Views

In chess, different pieces have unique movement patterns. This program solves the problem of finding the minimum number of moves for a special chess piece to reach every position on an n×n chessboard from the starting position (0, 0). The special piece moves in an L-shape pattern defined by parameters a and b. From position (x1, y1), it can move to (x2, y2) where: x2 = x1 ± a, y2 = y1 ± b x2 = x1 ± b, y2 = y1 ± a Algorithm Approach We use Breadth-First Search (BFS) to find the ...

Read More

Using djoser in Django for token authentication without views

Ath Tripathi
Ath Tripathi
Updated on 26-Mar-2026 2K+ Views

Djoser is a Django REST authentication library that simplifies token-based authentication. It provides ready-to-use endpoints for user registration, login, and token generation without requiring custom views. Installation First, create a Django project and install the required packages ? pip install djoser pip install djangorestframework Django Settings Configuration Add the required apps and authentication settings to your settings.py ? INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ...

Read More

How to add Social Share buttons in Django?

Ath Tripathi
Ath Tripathi
Updated on 26-Mar-2026 3K+ Views

Social share buttons are essential for modern websites, allowing users to share content across platforms like Facebook, Twitter, and LinkedIn. Django provides an easy way to implement these features using the django-social-share package. Installation First, install the required package ? pip install django-social-share Project Setup Configure Settings Add the package to your Django settings ? # settings.py INSTALLED_APPS += ['django_social_share'] URL Configuration Set up the main project URLs ? # project/urls.py from django.contrib import admin from django.urls import path, include urlpatterns = [ ...

Read More

Smooth profiling in Django

Ath Tripathi
Ath Tripathi
Updated on 26-Mar-2026 653 Views

In this article, we are going to implement Django profiling using django-silk. This tool provides detailed information about your application's performance, including GET requests, database queries, and other essential metrics for monitoring your website in production environments. Django Silk is particularly valuable for real-world project deployments where performance monitoring is critical. Installation First, create a Django project and app with basic settings configured. Then install the django-silk package ? pip install django-silk Configuration Settings Configuration In your settings.py, add the following configuration ? MIDDLEWARE = [ ...

Read More

Django – Showing model data directly into table with sorting and pagination

Ath Tripathi
Ath Tripathi
Updated on 26-Mar-2026 3K+ Views

In this article, we will see how to make a table in Django which will render model data. We are not going to use the standard tag of HTML. We will use the django_tables2 library which provides features to directly show Django model data in a table with sorting and pagination. Installing django_tables2 First, install the django_tables2 package ? pip install django_tables2 Add it to your settings.py ? INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', ...

Read More
Showing 3981–3990 of 61,299 articles
« Prev 1 397 398 399 400 401 6130 Next »
Advertisements