
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

1K+ Views
The activity selection problem selects the maximum number of non-overlapping activities from a given set. Each activity has a start and finish time, and a single person can perform only one activity at a time. Problem Statement You are given n activities, each defined by a start time and a finish time. The goal is to choose the maximum number of activities that a single person can perform without any overlap between the selected activities. Variable Notations Below are the variables used in the problem definition: N: Total number of activities S: ... Read More

5K+ Views
Knapsack is a classic problem that involves decision-making based on constraints. Suppose we have a knapsack with fixed capacity, and items with fixed values and sizes (it might be volume of the item or weight). We need to add items into the knapsack such that we pack the maximum value items. From the available combinations, we need to provide an optimized solution. There are three types of knapsack problems 0-1 Knapsack: We can either pick an item or not (0 or 1). Fractional Knapsack: We can pick a part of an ... Read More

285 Views
In Python, we may go through the matrices that are sorted in a particular order. A common case is a matrix where each row and each column is sorted in increasing order, and this does not mean that the entire matrix is sorted. In such cases, we need to extract all elements and print them in a fully sorted order. Row and Column-wise Sorted Matrix? A row and column-wise sorted matrix means each row is sorted from left to right, and each column is sorted from top to bottom. For example, let's consider the following matrix - matrix = ... Read More

28K+ Views
In Python, a list is a collection of ordered and mutable elements enclosed in square braces[]. Each element in a list has a unique position index, starting from 0. It can accept duplicate elements. In some cases, we may need to check if all the elements in a list are identical or not to detect a special condition in algorithms. Let's go through the different methods to check if all elements in a list are the same or not. Using set() function The Python set() function (built-in) is an unordered collection of unique elements. To check if all elements in a list ... Read More

150 Views
In Python, a string is one of the data structures that is a sequence of characters enclosed within single quotes '' or double quotes "". It is immutable, i.e., once a string is created, it cannot be changed. When we want to generate two output strings based on character occurrence in Python, we have to follow the steps below - First, we need to initialize a dictionary or use the collections.Counter class to count the frequency of each character in the input string. Next, we have to go through the input ... Read More

2K+ Views
In a given sentence there may be a word which get repeated before the sentence ends. In this python program, we are going to catch such word which is repeated in sentence. Below is the logical steps we are going to follow to get this result.Splits the given string into words separated by space.Then we convert these words into Dictionary using collectionsTraverse this list of words and check which first word has the frequency > 1Program - Find the Repeated WordIn the below program we use the counter method from the collections package to keep a count of the words.Example Live ... Read More

563 Views
Correlation is a statistical term to measure the relationship between two variables. If the relationship is string, means the change in one variable reflects a change in another variable in a predictable pattern then we say that the variables are correlated. Further the variation in first variable may cause a positive or negative variation in the second variable. Accordingly, they are said to be positively or negatively correlated. Ideally the value of the correlation coefficient varies between -1 to +1.If the value is +1 or close to it then we say the variables are positively correlated. And they vary in ... Read More

447 Views
Tkinter is the GUI module of python. It uses various message display options which are in response to the user actions or change in state of a running program. The message box class is used to display variety of messages like confirmation message, error message, warning message etc.Example-1The below example shows display of a message with the background colour, font size and colour etc customizable.import tkinter as tk main = tk.Tk() key = "the key to success is to focus on goals and not on obstacles" message = tk.Message(main, text = key) message.config(bg='white', font=('times', 32, 'italic')) message.pack() ... Read More

1K+ Views
A stopwatch is used to measure the time interval between two events usually in seconds to minutes. It has various usage like in sports or measuring the flow of heat, current etc in an industrial setup. Python can be used to creat a stopwatch by using its tkinter library.This library will have the GUI features to create a stopwatch showing the Start, Stop and Reset option. The key component of the program is using the lable.after() module of tkinter.label.after(parent, ms, function = None) where parent: The object of the widget which is using this function. ms: Time in miliseconds. function: ... Read More

184 Views
Set bits are the bits representing 1 in the binary form of a number. In this article we will see how to count the number of set bits in a given decimal number.#53 in binary is: 110101 The number of set bits is the number of ones. Here it is 4.In the below program we take the number and convert it to binary. As the binary conversion contains 0b as the first two characters, we remove it using string splitting technique. Then use a for loop to count each bit of the binary number if that value of the digit ... Read More