Found 10784 Articles for Python

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

karthikeya Boyini
Updated on 23-Jun-2020 16:09:56

834 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 Cyclic Redundancy Check

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

6K+ Views

For detecting errors in digital data CRC is used, this is a good technique in detecting the transmission errors. In this technique mainly binary division is applied. In these technique, cyclic redundancy check bits are present which is a sequence of redundant bits, these bits are appended to the end of data unit so that the resulting data unit becomes exactly divisible by a second which is predetermined binary number. At the destination side, the incoming data is divided by the same number, if there is no remainder then assumed that data is correct and it’s ready to accept. A ... Read More

Python program to create a sorted merged list of two unsorted list

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

433 Views

Here two user input list is given, the elements of two lists are unsorted. Our task is to merged these two unsorted array and after that sort the list. Example Input: A [] = {100, 50, 150} B [] = {200, 30, 20} Output: Merge List:{20, 30, 50, 100, 150, 200} Algorithm Step 1: first we create two user input list. Step 2: Final merge list size is (size of the first list + the size of the second list). Step 3: then sort two list using sort() method. Step ... Read More

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

karthikeya Boyini
Updated on 23-Jun-2020 16:11:30

1K+ 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

Find average of a list in python?

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

730 Views

Python provides sum function for calculating n number of element. Here we use this function and then calculate average. Algorithm Step 1: input “size of the list” Step 2: input “Element” Step 3: using sum function calculate summation of all numbers. Step 4: calculate average. Example code # Average of a list A=list() n=int(input("Enter the size of the List ::")) print("Enter the number ::") for i in range(int(n)): k=int(input("")) A.append(int(k)) sm=sum(A) avg=sm/n print("SUM = ",sm) print("AVERAGE = ",avg) Output Enter the size of the List ::5 Enter the number:: 10 20 30 40 50 SUM = 150 AVERAGE = 30.0

Print powers using Anonymous Function in Python?

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

223 Views

Here we used anonymous (lambda) function inside the map() built-in function. In Python, anonymous function is defined without name, its defined using lambda keyword. Algorithm Step 1: input n Step 2: input p Step 3: use anonymous function. Step 4: display result. Example Code # To display the powers of any number using anonymous function n = int(input("Enter how many terms want to display??")) p = int(input("Enter the number want to calculate power ::")) # use anonymous function cal = list(map(lambda i: p ** i, range(n))) # display the result print("The total terms is ::>", ... Read More

Second most repeated word in a sequence in Python?

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

646 Views

The string is given, our task is to find out the second repeated word. Here we Counter(iterator) for creating dictionary which contains word as key and its frequency as value. Algorithm Step 1: Create user define list. Step 2: Then convert list into a dictionary. Step 2: Next get the values and sort them in descending order. Step 3: Then the second element is the second largest value. Step 4: Next again traverse whole dictionary and display key whose value is equal to second largest element. Example code # To print Second most repeated word in a ... Read More

Python program to find Intersection of two lists?

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

420 Views

Intersection operation means, we have to take all the common elements from List1 and List 2 and all the elements store in another third list. List1::[1, 2, 3] List2::[2, 3, 6] List3::[2, 3] Algorithm Step 1: input lists. Step 2: first traverse all the elements in the first list and check with the elements in the second list. Step 3: if the elements are matched then store in third list. Example code #Intersection of two lists def intertwolist(A, B): C = [i for i in A if i in B] ... Read More

Python program to find Union of two or more Lists?

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

485 Views

Union operation means, we have to take all the elements from List1 and List 2 and all the elements store in another third list. List1::[1, 2, 3] List2::[4, 5, 6] List3::[1, 2, 3, 4, 5, 6] Algorithm Step 1: Input two lists. Step 2: for union operation we just use + operator. Example code # UNION OPERATION A=list() B=list() n=int(input("Enter the size of the List ::")) print("Enter the Element of first list::") for i in range(int(n)): k=int(input("")) A.append(k) print("Enter the Element of second list::") for i in range(int(n)): ... Read More

Python program to count unset bits in a range.

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

152 Views

Given a positive a number and the range of the bits. Our task is to count unset bits in a range. Input : n = 50, starting address = 2, ending address = 5 Output : 2 There are '2' unset bits in the range 2 to 5. Algorithm Step 1 : convert n into its binary using bin(). Step 2 : remove first two characters. Step 3 : reverse string. Step 4 : count all unset bit '0' starting from index l-1 to r, where r is exclusive. Example Code # ... Read More

Advertisements