Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

Python | Find all close matches of input string from a list

Python | Find all close matches of input string from a list We are given a list of pattern strings and a single input string. We need to find all possible close good enough matches of input string into list of pattern strings. Examples: Input : patterns = [‘ape’, ‘apple’, ‘peach’, ‘puppy’], input = ‘appel’…
Read more

Generating random strings until a given string is generated

Generating random strings until a given string is generated Given the string, the task is to generate the same string using the random combination of special character, numbers, and alphabets. Examples : Input : GFG Output :n4W mK7 k1x q;;, !g . . . . . GF, GFf GFp GFG Target matched after 167 iterations…
Read more

Program to create grade calculator in Python

Creating a Grade Calculator Program in Python In this blog post, we will walk through the process of creating a Python program that functions as a grade calculator. This program will take a student’s score as input and determine the corresponding grade based on a predefined grading scale. We will discuss the algorithm used, provide…
Read more

Python | Merging two Dictionaries

Python | Merging two Dictionaries There are various ways in which Dictionaries can be merged by the use of various functions and constructors in Python. In this article, we will discuss few ways of merging dictionaries. Using the method update() By using the method update() in Python, one list can be merged into another. But…
Read more

Ways to sort list of dictionaries by values in Python – Using lambda function

Ways to sort list of dictionaries by values in Python – Using lambda function Sorting has always been a useful utility in day-to-day programming. Dictionary in Python is widely used in many applications ranging from competitive domain to developer domain(e.g. handling JSON data). Having a knowledge to sort dictionaries according to its values can prove…
Read more

Ways to sort list of dictionaries by values in Python – Using itemgetter

Ways to sort list of dictionaries by values in Python – Using itemgetter Previous article of this segment dealt with sorting list of dictionaries by values using lambda function. This article aims at performing this functionality using itemgetter and showing visible differences. Itemgetter can be used instead of lambda function to achieve the similar functionality.…
Read more

Python | Ways to remove a key from dictionary

Python | Ways to remove a key from dictionary Dictionary is used in manifold practical applications such as day-day programming, web development and AI/ML programming as well, making it a useful container overall. Hence, knowing shorthands for achieving different tasks related to dictionary usage always is a plus. This article deals with one such task…
Read more

Python program to find the sum of all items in a dictionary

Python program to find the sum of all items in a dictionary Given a dictionary in Python, write a Python program to find the sum of all Items in the dictionary. Examples: Input : {‘a’: 100, ‘b’:200, ‘c’:300} Output : 600 Input : {‘x’: 25, ‘y’:18, ‘z’:45} Output : 88 Approach #1 : Using Inbuilt…
Read more

Python dictionary with keys having multiple inputs

Python dictionary with keys having multiple inputs How to create a dictionary where a key is formed using inputs? Let us consider an example where have an equation for three input variables, x, y and z. We want to store values of equation for different input triplets. Example 1: # Python code to demonstrate a…
Read more

Handling missing keys in Python dictionaries

Handling missing keys in Python dictionaries In python, dictionaries are containers which map one key to its value with access time complexity to be O(1). But in many applications, the user doesn’t know all the keys present in the dictionaries. In such instances, if user tries to access a missing key, an error is popped…
Read more