Found 34494 Articles for Programming

Difference between == and is operator in python.

George John
Updated on 30-Jul-2019 22:30:23

752 Views

is and equals(==) operators are mostly same but they are not same. is operator defines if both the variables point to the same object whereas the == sign checks if the values for the two variables are the same. Example Code # Python program to # illustrate the # difference between # == and is operator # [] is an empty list list1 = [] list2 = [] list3=list1 if (list1 == list2): print("True") else: print("False") if (list1 is list2): print("True") else: print("False") if (list1 is list3): print("True") else: print("False") Output True False True

Zip function in Python to change to a new character set.

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

74 Views

Given a 26 letter character set, here we are using a new character set. And another character set just like alphabet set (a, b, c........z), then our task is to make a relation between new character set and that alphabet set. Example New character set: qwertyuiopasdfghjklzxcvbnm Input: "wwmm" Output: bbzy Algorithm Step 1: Given a new character set and input the string to make a relation. Step 2: and the original character set also given below. Step 3: Create a dictionary, we use here map technique, we map the English character set and new given character set, ... Read More

Python program to check if binary representation of two numbers are anagram.

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

565 Views

Given two numbers. Our task is to check whether they are anagrams of each other or not in binary representation. We can solve this problem quickly in python using Counter (iterable) method and Dictionary Comparison. Examples Input: a = 8, b = 16 Output : Yes Binary representations of both numbers have same 0s and 1s. Algorithm Step 1 : Given two numbers. Step 2 : Convert both number into its binary using bin() function and remove first two characters because of bin(). Step 3 : Since binary representation of both numbers could differ in length ... Read More

Print m multiplies of n without using any loop in Python.

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

196 Views

Given a number n, print m multiplies of n without using any loop. Here we use recursive function. Examples Input: n = 15 Output: 15 10 5 0 5 10 15 Algorithm Step 1: Given n. Step 2: If we are moving back toward the n and we have reached there, then we are done. Step 3: If we are moving toward 0 or negative. Step 4: If m is greater, then 5, recursive function with true flag else recursive function is false. Step 5: If m is not greater than 5 then flag is false. ... Read More

Python program to find missing and additional values in two lists?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

1K+ Views

In set theory, the complement of a set A refers to elements not in A. the relative complement of A with respect to a set B, also termed the difference of Sets A and B. We just apply this principle here. Python has difference function. Algorithm Step 1 : first we create two user input list. A & B Step 2 : Insert A and B to a set. Step 3 : for finding the missing values of first list we apply difference function, difference of B from A. Step 4 : for finding the Additional ... Read More

Python program to check a sentence is a pangrams or not.

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

314 Views

Given a sentence. Our task is to check whether this sentence is pan grams or not. The logic of Pan grams checking is that words or sentences containing every letter of the alphabet at least once. To solve this problem we use set () method and list comprehension technique. Example Input: string = 'abc def ghi jkl mno pqr stu vwx yz' Output: Yes // contains all the characters from ‘a’ to ‘z’ Input: str='python program' Output: No // Does not contains all the characters from ‘a’ to 'z' Algorithm Step 1: create a string. Step 2: ... Read More

Python program to extract ‘k’ bits from a given position?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

2K+ Views

This function is use to extract k bits from pos position and returns the extracted value. Here we use python slicing technique. Example Input:: number=170 K=5 Pos=2 Output=21 Algorithm Extractionbit(no, k, pos) /*user input number is stored in variable no, extracted bit is stored in variable k and the position of bit is pos. */ Step 1 : first convert the number into its binary form using bin(). Step 2 : remove the first two character. Step 3 : then extracting k bits from starting ... Read More

Python program to reverse each word in a sentence?

George John
Updated on 30-Jul-2019 22:30:23

3K+ Views

Here we use python built in function. First we split the sentence into a list of word. Then reverse each word and creating a new list ,here we use python list comprehension technique and last joining the new list of words and create an new sentence. Example Input :: PYTHON PROGRAM Output :: NOHTYP MARGORP Algorithm Step 1 : input a sentence. And store this in a variable s. Step 2 : Then splitting the sentence into a list of words. w=s.split(“”) Step 3 : Reversing each word and creating a new list of ... Read More

Python program to list the difference between two lists.

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

1K+ Views

In this problem given two lists. Our tasks is to display difference between two lists. Python provides set() method. We use this method here. A set is an unordered collection with no duplicate elements. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference. Example Input::A = [10, 15, 20, 25, 30, 35, 40] B = [25, 40, 35] Output: [10, 20, 30, 15] Explanation difference list = A - B Algorithm Step 1: Input of two arrays. Step 2: convert the lists into sets explicitly. Step 3: simply reduce one ... Read More

Python program to print all distinct elements of a given integer array.

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

1K+ Views

Given an integer array. The elements of the array may be duplicate.Our task is to display the distinct values. Example Input::A=[1, 2, 3, 4, 2, 3, 5, 6] Output [1, 2, 3, 4, 5, 6] Algorithm Step 1: input Array element. Step 2: Then pick all the elements one by one. Step 3: then check if the picked element is already displayed or not. Step 4: use one flag variable which initialized by 0.if the element is displayed earlier flag variable is 1 and if the element is not displayed earlier flag variable is 0. ... Read More

Advertisements