Found 34494 Articles for Programming

Python program to find k'th smallest element in a 2D array

Arushi
Updated on 30-Jul-2019 22:30:23

372 Views

One n×n user input integer matrix is given and the value of k. Our task is to find out k'th smallest element in a 2D array. Here we use heapq mudule.Heap queue (or heapq) in Python. In Python, it is available using “heapq” module. The technique of this module in python is that each time the smallest of heap element is popped (min heap).nsmallest () method is used to get n least values from a data frame or a series. Example Input Array is:: 10 20 20 40 15 45 40 30 32 33 30 50 ... Read More

Python program to generate all possible valid ID address from given string

Vikyath Ram
Updated on 30-Jul-2019 22:30:23

672 Views

String is given. String contains only digit. Our task is to check all possible valid IP address combinations. Here first we check the length of the string then split by ".". Then we check the different combination of ".". Example Input : "255011123222" It's not a valid IP address. Input : 255011345890 Valid IP address is 255.011.123.222 Algorithm Step 1: First check the length of the string. Step 2: Split the string by ".". We will place 3 dots in the given string. W, X, Y, and Z are numbers from 0-255 the numbers cannot be ... Read More

Python Program to find mirror characters in a string

Sarika Singh
Updated on 23-Nov-2022 07:25:19

3K+ Views

This article teaches you how to write a python program to find mirror characters in a string. Let us first understand what mirror characters in a string are. Two identical alphabetically positioned characters, one from the front and the other from the back, are known as mirror characters. For example, the alphabet a's mirror character is "z, " "b's" is "y, " and so on. Input-Output Scenario Following is an input and its output example of mirror characters in a string − Input: p = 3 Input string = Coding Output: Cowrmt Here, the alphabets “d”, “i”, “n”, “g” ... Read More

Calendar function in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

1K+ Views

Python has an in built module called calendar which operation is related to calendar. There are some calendar functions in Python. calendar(year, w, l, c) This function shows the year, width of characters, no. of lines per week and column separations. Example print ("The calendar of 2014 is : ") print (calendar.calendar(2014, 3, 1, 4)) Output The calendar of year 2014 is : 2014 January ... Read More

Inplace operator in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

5K+ Views

Definition - In-place operation is an operation that changes directly the content of a given linear algebra, vector, matrices(Tensor) without making a copy. The operators which helps to do the operation is called in-place operator. Eg: a+= b is equivalent to a= operator.iadd(a, b) There are some operators are used for In-place operation. iadd() This function is used to assign the current value and add them. This operator does x+=y operation. In case of strings, numbers assigning is not performed. Example a =operator.iadd(1, 3); print ("The result after adding : ", end="") print(a) Output ... Read More

Statistical Functions in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

3K+ Views

Python has ability to solve the mathematical expression, statistical data by importing statistic keyword. Python can do various types of statistical and mathematical operations. These functions calculate the average value from a sample or population. mean () Arithmetic mean value (average) of data. harmonic_mean () Harmonic mean value of data. median () Median value (middle value) of data. median__low() Low median value of data. median__high() High median value of data. median__grouped() Median of the grouped data and also calculate the 50th percentile of the grouped data. ... Read More

Python program to find the size of the largest subset of anagram words

Sarika Singh
Updated on 04-Apr-2023 11:59:46

254 Views

This article teaches you how to write a Python program to find the size of the largest subset of anagram words Every character of the rearranged string or number must also be a component of another string or number in order for the condition of an anagram to exist. To put it another way, a string is said to be an anagram of another if the second is just the first string rearranged. As an illustration, the words The program and rogPrma are anagrams, as are the words Code and doCe. Input-Output Scenarios Lets take an input and its output ... Read More

Python Program to check if two given matrices are identical

Sarika Singh
Updated on 23-Nov-2022 07:22:21

3K+ Views

Matrix refers to a collection of numbers arranged in rows and columns to form a rectangular array. The numbers make up the matrix's entries, or elements. We need to create a Python function to determine whether two given matrices are identical. In other words, we say that two matrices are identical if all of the elements in their respective places are the same. Identical Matrices Two matrices are only considered equal if and when they meet the requirements listed below − There should be an equal number of rows and columns in each matrices. The identical corresponding items should ... Read More

Python program to check whether a given string is Heterogram or not

Rishi Raj
Updated on 23-Jun-2020 16:12:12

1K+ Views

Here one string is given then our task is to check weather a given string is Heterogram or not.The meaning of heterogram checking is that a word, phrase, or sentence in which no letter of the alphabet occurs more than once. A heterogram may be distinguished from a pangram which uses all of the letters of the alphabet.ExampleString is abc def ghiThis is Heterogram (no alphabet repeated)String is abc bcd dfhThis is not Heterogram. (b, c, d are repeated)AlgorithmStep 1: first we separate out list of all alphabets present in sentence. Step 2: Convert list of alphabets into set because ... Read More

Write Python program to find duplicate rows in a binary matrix

Paul Richard
Updated on 23-Jun-2020 16:19:16

263 Views

Given a binary matrix contains 0 and 1, our task is to find duplicate rows and print it.Python provides Counter() method which is used here.ExampleInput: 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 Output: (1, 1, 1, 1) (0, 0, 0, 0)AlgorithmStep 1: Create a binary matrix, only 0 and 1 elements are present. Step 2: Which will have rows as key and it’s frequency as value. Lists are mutable so first, we will cast each row (list) into a tuple. Step 3: Create a dictionary using the counter method. Step 4: ... Read More

Advertisements