AmitDiwan has Published 10744 Articles

Python Program to Determine Whether a Given Number is Even or Odd Recursively

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 13:03:21

867 Views

When it is required to check if a given number is an odd number or an even number using recursion, recursion can be used.The recursion computes output of small bits of the bigger problem, and combines these bits to give the solution to the bigger problem.ExampleBelow is a demonstration for ... Read More

Python Program that Displays which Letters are in the Two Strings but not in Both

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 13:01:30

290 Views

When it is required to display the letters that occur in both strings separately, but are not repeated, the user input is taken, and the ‘list’ and ‘set’ are used to achieve the same.A list can be used to store heterogeneous values (i.e data of any data type like integer, ... Read More

Python Program that Displays which Letters are in the First String but not in the Second

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 13:00:07

470 Views

When it is required to display the letters that are present in the first string but not in the second string, two string inputs are taken from user. The ‘set’ is used to find the difference between the two strings.Python comes with a datatype known as ‘set’. This ‘set’ contains ... Read More

Python Program to Create a Dictionary with Key as First Character and Value as Words Starting with that Character

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:54:12

2K+ Views

When it is required to create a dictionary with the key as the first character and the associated value as the word which is the starting of that character, the s’plit’ method, a dictionary and simple ‘if’ condition is used.ExampleBelow is a demonstration for the same − Live Demomy_string=input("Enter the string ... Read More

Python Program to Count the Frequency of Words Appearing in a String Using a Dictionary

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:51:19

7K+ Views

When it is required to count the frequency of words that appear in a string with the help of dictionary, the ‘split’ method is used to split the values, and a list comprehension is used.The list comprehension is a shorthand to iterate through the list and perform operations on it.A ... Read More

Python Program to Form a Dictionary from an Object of a Class

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:49:57

3K+ Views

When it is required to form a dictionary with the help of an object and class, a class is defined. An ‘init’ function is defined, that assigns values to variables. An instance of the class is created, and the init function is called.ExampleBelow is a demonstration for the same − Live ... Read More

Python Program to Multiply All the Items in a Dictionary

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:48:43

866 Views

When it is required to multiply all the elements in a dictionary, the key values in the dictionary are iterated over. The key is multiplied with the previous key, and output is determined.The dictionary is a set of key-value pairs.ExampleBelow is a demonstration for the same − Live Demomy_dict = {'Jane':99, ... Read More

Python Program to Generate a Dictionary that Contains Numbers (between 1 and n) in the Form (x,x*x).

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:47:14

2K+ Views

When it is required to generate a dictionary that contains numbers within a given range in a specific form, the input is taken from the user, and a simple ‘for’ loop is used.ExampleBelow is a demonstration for the same − Live Demomy_num = int(input("Enter a number.. ")) my_dict = dict() for ... Read More

Python Program to Concatenate Two Dictionaries Into One

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:44:07

2K+ Views

When it is required to concatenate two dictionaries into a single entity, the ‘update’ method can be used.A dictionary is a ‘key-value’ pair.Below is a demonstration for the same −Example Live Demomy_dict_1 = {'J':12, 'W':22} my_dict_2 = {'M':67} print("The first dictionary is :") print(my_dict_1) print("The second dictionary is :") print(my_dict_2) my_dict_1.update(my_dict_2) ... Read More

Python Program to Reverse a String without using Recursion

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 12:37:06

669 Views

When it is required to reverse a string without using recursion technique, simple negative indexing can be used.Indexing helps the values to access the elements at a specific index.ExampleBelow is a demonstration for the same − Live Demomy_string = str(input("Enter a string that needs to be reversed: ")) print("The string after ... Read More

Advertisements