Found 26504 Articles for Server Side Programming

Check if the number formed by concatenating all array elements is a Harshad number or not

Shubham Vora
Updated on 10-Aug-2023 10:19:29

142 Views

In this problem, we have given the array of integers. We need to combine all elements in a single integer and check if it is a Harshad number. Before we move with the solution, let’s understand Harshad number. All numbers are Harshad numbers which are divisible by the sum of their digits. For example, 12 is Harshad number, as 12 is divisible by 3 = 1 + 2. To solve the problem, we can combine all array elements, and after that, we can check whether the resultant number is the Harshad number. Problem statement – We have given an array ... Read More

Check if all characters of a string can be made equal by increments or decrements

Shubham Vora
Updated on 10-Aug-2023 10:17:50

226 Views

In this problem, we need to check if we can make all characters of strings equal by increment and decrement operations. We can get the weight of each character based on their ASCII values and check whether the total weight can be used to make all characters equal. Problem statement – We have given string str of length N containing lowercase alphabetical characters. We need to check whether we can make all characters of the string equal by choosing any of two characters, increasing one, and decreasing another by 1. If possible, print ‘yes’, else ‘no’. Sample examples Input– ... Read More

Creating a Nested Dictionary using a given List in Python

Atharva Shah
Updated on 09-Aug-2023 17:13:50

1K+ Views

Python dictionaries are flexible data structures that hold key-value pairs effectively. A nested dictionary is a hierarchical data structure to organize and manage large amounts of data. This article shows how to construct a nested dictionary from a given list, enabling dictionary users to perform a variety of tasks. Syntax Nest multiple levels of dictionaries to accommodate complex data structures. nested_dict = { 'outer_key': { 'inner_key': 'value' } } Algorithm 1. Create a new dictionary to contain the layered structure. 2. Go through the given list iteratively. 3. Extract the necessary information for keys and ... Read More

How to Create Multiple Toolbars in wxPython

Atharva Shah
Updated on 09-Aug-2023 17:12:31

149 Views

In the realm of GUI programming, wxPython has emerged as a powerful and versatile library, empowering developers to craft stunning graphical user interfaces with ease. Among the many essential components, toolbars play a vital role in providing users with quick access to various functionalities. In this tutorial, we'll dive into the art of creating multiple toolbars using wxPython. By the end, you'll be equipped with the knowledge to enhance your GUI applications with multiple toolbars, thereby offering an improved user experience. Installation wxPython Library for GUI Prototyping As a wrapper for the C++ library wxWidgets, wxPython allows ... Read More

Create list of Tuples using for Loop using Python

Atharva Shah
Updated on 09-Aug-2023 17:09:36

983 Views

Python's key data structures are lists and tuples. Once elements of tuples are set they cannot be changed. This is called immutability. But list elements can be modified after initialization. When dealing with data that needs to be grouped together, a for loop is used to create tuple lists. Lists are more adaptable than tuples due to their ability to be modified. This tutorial demonstrates creating a list of tuples using a for loop, simplifying repetitive tasks. Syntax for variable in iterable: # loop code Basic Operations on Tuples Example # Initializing my_tuple = ... Read More

How to Create a Dictionary Of Tuples in Python

Atharva Shah
Updated on 09-Aug-2023 17:07:55

2K+ Views

This walkthrough is all about creating a dictionary of tuples in Python. This data structure stores key-value pairs. By combining dictionaries and tuples, a dictionary of tuples can be created. The benefit is organized and accessible data in a structured format. Becomes easy to represent multiple values for each key, such as student grades or contact information. Let us see how this efficiently stores and retrieves complex data. Syntax Ensure Python is installed on your system for its simplicity and readability. Create a dictionary of tuples using the following syntax: dictionary_name = {key1: (value1_1, value1_2, ...), key2: ... Read More

How to Create Acronyms from Words Using Python

Akshitha Mote
Updated on 22-Jul-2025 18:40:42

3K+ Views

The acronym is an abbreviated version of a sentence, which means it is the short form of the given sentence. It is formed from each word's first character in the given sentence. For example, CPU is an acronym of Central Processing Unit. In this article, we will learn how to create acronyms from words using Python. Scenario Input: my_str = "Automatic Teller Machine" Output: ATM Explanation: Here, the given string “Automatic Teller Machine”, we have created an acronym from it by considering first character of each word. Algorithm to Create Acronyms from Words The following are the steps ... Read More

Python - Create a string made of the first and last two characters from a given string

Atharva Shah
Updated on 09-Aug-2023 16:35:01

3K+ Views

This tutorial is all about string slicing. This involves creating a new string using the first and last two characters of a given string. Examples include using string slicing to extract the first two characters of a string. Such as "he" and "lo, " and combining these slices to create a new string with the first and last two characters. String manipulation methods prove handy while working with large strings or performing specific operations on a string's individual components. Let us explore several ways to handle this. Algorithm Begin with the string that has ... Read More

Removing Odd Elements From List in Python

Sai Mohan Pulamolu
Updated on 09-Aug-2023 16:32:39

6K+ Views

In Python, lists are a versatile data structure that allows you to store and manipulate collections of items. There may be use cases where you need to remove specific elements from a list based on certain criteria. In this tutorial, we will learn how to remove odd elements from a list in Python. Using a For Loop and remove() method The approach is to use a for loop to iterate through each element of the list and check if the element is odd or even and then use the remove() method to remove it from the list. Syntax remove() remove(item) ... Read More

How to Create a List of Tuples in Python?

Atharva Shah
Updated on 09-Aug-2023 16:28:05

386 Views

In Python, creating a list of tuples is a flexible data structure for storing many items. Tuples are immutable, ordered collections that are suitable for grouping similar items. This tutorial will guide you through this with several examples to build and handle lists of tuples. Understanding Tuples Tuples are ordered collections of elements. Lists are mutable collections of elements enclosed in square brackets, that combine with tuples to form a list of tuples. List comprehension gives compact code. It also unpacks and assigns variables to each member necessary for quick access. Nesting tuples within lists ... Read More

Advertisements