Python Articles

Page 803 of 855

Write Python program to find duplicate rows in a binary matrix

Paul Richard
Paul Richard
Updated on 23-Jun-2020 402 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

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

Rishi Raj
Rishi Raj
Updated on 23-Jun-2020 2K+ 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

Python program to find Largest, Smallest, Second Largest, and Second Smallest in a List?

karthikeya Boyini
karthikeya Boyini
Updated on 23-Jun-2020 2K+ Views

Array is given, we have to find out maximum, minimum, secondlargest, second smallest number.AlgorithmStep 1: input list element Step 2: we take a number and compare it with all other number present in the list. Step 3: get maximum, minimum, secondlargest, second smallest number.Example code# To find largest, smallest, second largest and second smallest in a List    def maxmin(A):       maxi = A[0]       secondsmax = A[0]       mini = A[0]       secondmini = A[0]       for item in A:    if item > maxi:       maxi ...

Read More

Python code to print common characters of two Strings in alphabetical order

karthikeya Boyini
karthikeya Boyini
Updated on 23-Jun-2020 1K+ Views

Two user input strings are given, our task is to print all the common characters in alphabetical order.ExampleInput: string1: python string2: program Output: opExplanationThe letters that are common between the two strings are o (1 times), p (1 time)AlgorithmStep 1: first we take two input string. Step 2: next we will do to convert these two strings into counter dictionary. Step 3: Now find common elements between two strings using intersection ( ) property. Step 4: Resultant will also be a counter dictionary having common elements as keys and their common frequencies as value. Step 5: Use elements () method ...

Read More

Python program to move spaces to front of string in single traversal

Samual Sam
Samual Sam
Updated on 23-Jun-2020 593 Views

Given a string that has set of words and spaces, our task is to move all spaces to front of string, by traversing the string only once. We will solve this problem quickly in Python using List Comprehension.ExampleInput: string = "python program" Output: string= “ pythonprogram"AlgorithmStep1: input a string with word and space. Step2: Traverse the input string and using list comprehension create a string without any space. Step 3: Then calculate a number of spaces. Step 4: Next create a final string with spaces. Step 5: Then concatenate string having no spaces. Step 6: Display string.Example Code# Function to ...

Read More

String slicing in Python to rotate a string

karthikeya Boyini
karthikeya Boyini
Updated on 23-Jun-2020 5K+ Views

A string is given, our task is to slicing the string into two way. One is clockwise and another anticlockwise.1. Left (Or anticlockwise) rotate the given string by d elements (where d pythonprogram Left Rotation: thonprogrampy Right Rotation: ampythonprogr

Read More

Python Program to calculate n+nm+nmm.......+n(m times).

Samual Sam
Samual Sam
Updated on 23-Jun-2020 614 Views

Here n is given value which is positive number m is the number of times till which the series run. Our task is to calculate this series.AlgorithmStep 1: Input n, m; Step 2: Converting the number to string. Step 3: Initializing result as number and string. Step 4: Adding remaining terms. Step 5: Concatenating the string making n, nn, nnn... Step 6: Before adding converting back to integer. Step 7: return sum.Example Code# Python program to sum the series def sumofseries(n, m):    str1 = str(n)    sum1 = n    sumofstr1 = str(n)    for i in range(1, m): ...

Read More

Get emotions of images using Microsoft emotion API in Python?

Samual Sam
Samual Sam
Updated on 23-Jun-2020 235 Views

Every human being have emotions just like happy, sad, neutral, surprise, sorrow etc., if we create the emotions of images like happy, sad, neutral, surprise, etc. in Python. We can use Microsoft emotion API for any development purpose.We can easily elaborate all these emotions using Microsoft emotion API's.Example Codeimport http.client, urllib.request import urllib.parse, urllib.error import base64, sys import simplejson as json # replace with subscription_key # you obtained after registration subscription_key = '23d39244dbe55173214b56ab45d56cla' headers = {    # Request for headers. And also replace the placeholder key with    # our subscription key.    'Content-Type': 'application/json',    'Ocp-Apim-Subscription-Key': ...

Read More

How to use enums in Python classes?

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Jun-2020 320 Views

There is a module name "enum" in python with the hep of which enum is used in python.#import enum import enum # use enum in class class Car(enum.Enum):    suzuki = 1    Hyundai = 2    Dezire = 3 print ("All the enum values are : ") for c in (Car):    print(c)

Read More

How to replace backward "" slash from a string

Malhar Lathkar
Malhar Lathkar
Updated on 23-Jun-2020 722 Views

In Python it does give the desired result>>> var  = "aaa\bbb\ccc and ddd\eee" >>> var.split('') ['aaa', 'bbb', 'ccc and ddd', 'eee']

Read More
Showing 8021–8030 of 8,547 articles
« Prev 1 801 802 803 804 805 855 Next »
Advertisements