Found 35163 Articles for Programming

Concatenated string with uncommon characters in Python?

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

682 Views

Here two strings are given, first we have to remove all the common element from the first string and uncommon characters of the second string have to be concatenated with uncommon element of first string. Example Input >> first string::AABCD Second string:: MNAABP Output >> CDMNP Algorithm Uncommonstring(s1, s2) /* s1 and s2 are two string */ Step 1: Convert both string into set st1 and st2. Step 2: use the intersection of two sets and get common characters. Step 3: now separate out characters in each string which are not common in both string. Step 4: ... Read More

Python program to print all the common elements of two lists.

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

845 Views

Given two lists, print all the common element of two lists. Examples − Input : L1 = [5, 6, 7, 8, 9] L2 = [5, 13, 34, 22, 90] Output : {5} Explanation The common elements of both the list is 5. Algorithm Step1 : create two user input lists. Step2 : Convert the lists to sets and then print set1&set2. Step3 : set1 and set2 returns the common elements set, where set1 is the list1 and set2 is the list2. Example Code # Python ... Read More

Python program to check if both halves of the string have same set of characters.

karthikeya Boyini
Updated on 23-Jun-2020 16:01:38

167 Views

Given a string, our task is to check if both halves of the string have the same set of characters or not. To solve this problem we first split the string from the middle, so we get two halves, now we check each halves having the same set of characters or not. If the length of the string is not even then ignore the middle element and check for the rest.AlgorithmStep 1: Given a string. Step 2: Break the input string into two parts. Step 3: Then convert both parts into a dictionary using Counter(iterator) method and each dictionary contains ... Read More

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

Samual Sam
Updated on 23-Jun-2020 16:03:14

380 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

Python program to display Astrological sign or Zodiac sign for a given data of birth.

George John
Updated on 23-Jun-2020 16:02:25

3K+ Views

Given date of birth, our task is to display astrological sign or Zodiac sign.ExamplesInput : Day = 13, Month = November Output : Scorpio.AlgorithmStep 1 : input date of birth. Step 2 : checks month and date within the valid range of a specified zodiac. Step 3 : display zodiac sign.Example Codedef zodiac_sign(day, month):    # checks month and date within the valid range    # of a specified zodiac    if month == 'december':       astro_sign = 'Sagittarius' if (day < 22) else 'capricorn'    elif month == 'january':       astro_sign = 'Capricorn' if (day ... Read More

Python program to create 3D list.

karthikeya Boyini
Updated on 23-Jun-2020 16:03:40

2K+ Views

3D list means 3D array. In this program we create 3D array with integer elements.ExampleInput: 3× 3 × 2 [[1, 1, 1], [2, 2, 2], [3, 3, 3]], [[4, 4, 4], [5, 5, 5], [6, 6, 6]]AlgorithmStep 1: given the order of 3D list. Step 2: using for loop we create list and print data.Example Code# Python program to created 3D list import pprint def print3D(i, j, k):    lst = [[ ['*' for cc1 in range(i)] for cc2 in range(j)] for r in range(k)]    return lst    # Driver Code    c1 = 3    c2 = 2 ... Read More

Python program to remove all duplicates word from a given sentence.

Ankith Reddy
Updated on 23-Jun-2020 16:04:23

456 Views

Given a sentence. Remove all duplicates words from a given sentence.ExampleInput: I am a peaceful soul and blissful soul. Output: I am a peaceful soul and blissful.AlgorithmStep 1: Split input sentence separated by space into words. Step 2: So to get all those strings together first we will join each string in a given list of strings. Step 3: now create a dictionary using the counter method which will have strings as key and their Frequencies as value. Step 4: Join each words are unique to form single string.Example Codefrom collections import Counter def remov_duplicates(st):    st = st.split(" ") ... Read More

Plotting graph using seaborn in python.

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

441 Views

Plotly's Python graphing library makes interactive, publication-quality graphs online. this graph is mainly used when we want to make line plots, scatter plots, area charts, bar charts, error bars, box plots, histograms, heatmaps, subplots, multiple-axes, polar charts, and bubble charts. Seaborn is a library for making statistical graphics in Python. It is built on top of matplotlib and it is integrated with pandas data structures. 1. We import seaborn, which is the only library necessary for this simple example. import seaborn as sns 2. We apply the default default seaborn theme, scaling, and color palette. sns.set() ... Read More

Python program to Display Hostname and IP address?

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

1K+ Views

Python provides gethostname(), gethostbyname() two function. gethostname() retrives the standard host name for the local machine. gethostbyname() retrives host information corresponding to a host name from a host database. Socket. gethostname() Socket. gethostbyname() Algorithm Step 1: use module socket. Step 2: use gethostname() retrives the standard host name for the local machine. Step 3: use gethostbyname() retrives host information corresponding to a host name from a host database. Example Code # Display hostname andIP address import socket def host_IP(): try: hname = socket.gethostname() ... Read More

Python program to reverse bits of a positive integer number?

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

2K+ Views

First convert number into binary using bin() function. Then skip the first two character of binary representation because bin() appends 0b as a prefix in a binary representation of the number and reverse the remaining part. From also character and reverse it till second last character from left. Convert a reversed binary string into integer. Algorithm integernumber(n, bit_size) /* n is the number and bit_size is the bitsize */ Step 1: first convert number into binary . Step 2: skip the first two characters of binary representation string and reverse. Step 3: remaining string and then append 0’s ... Read More

Advertisements