Found 26504 Articles for Server Side Programming

Python Program To Convert An Array List Into A String And Viceversa

Kavya Elemati
Updated on 24-Apr-2023 16:54:40

258 Views

Converting a list into a string One method for converting a list into a string is to iterate through all the items of a list and concatenate them into an empty string. Example lis=["I", "want", "cheese", "cake"] str="" for i in lis: str=str+i str=str+" " print(str) Output I want cheese cake Using Join Function Join is an in-built function in python which is used for joining the items of an iterable object (ex: list) using a separator which will be specified by the user. We can use the join ... Read More

Python Program To Get The Middle Element Of A Linked List In A Single Iteration

Kavya Elemati
Updated on 24-Apr-2023 17:24:17

2K+ Views

Linked list is used for storing the data in non-contiguous memory locations. The nodes containing the data items are linked using pointers. Each node consists of two fields. The first field is used for storing the data and the second field contains the link to the next node. Brute Force Technique To find the middle element of a linked list, the brute force technique is to find out the length of the linked list by iterating the entire linked list till NULL is encountered and then the length is divided by 2 to get the index of the middle element. ... Read More

Collections in Python

Kavya Elemati
Updated on 24-Apr-2023 16:47:24

5K+ Views

In python, collections are the containers used for storing the data. The built-in data structures in python are tuples, lists, sets and dictionaries. The collections class will provide additional data structures apart from the built-in data structures. Some of the data structures in the ‘collections’ module − Counter namedTuple orderedDict defaultDict Deque chainMap Counter It is the type of collection in which the elements will be stored as dictionary keys and the counts will be stored as dictionary values. Whenever you want to calculate the frequency of any item in a list, traditionally you would use a ... Read More

Python Program To Add Elements To A Linked List

Kavya Elemati
Updated on 24-Apr-2023 16:44:53

1K+ Views

What is a Linked List When data is not stored in continuous memory locations, it takes a lot of time to search all the memory locations to get the required data. To prevent this, we use Linked Lists. A linked list in Python is a data structure that stores items in an ordered sequence. It consists of nodes, where each node contains the item and a reference to the next node in the list. The first node is known as the head, while the last one is referred to as tail. Linked lists are used for efficient insertion and deletion ... Read More

Haskell Program to Print Right Triangle Star Pattern

Akhil Sharma
Updated on 24-Apr-2023 11:39:31

298 Views

In haskell we can use mapM, forM as well as recursive function to create a simple right triangle star pattern. What is a Right Triangle Star Pattern? A right triangle pattern is a series of asterisks or other characters arranged in a triangular shape. In the case of a right triangle pattern, the base of the triangle is the longest side and is aligned with the horizontal axis, while the other two sides form a right angle. The number of asterisks or characters in each row of the triangle decreases as you move up the triangle, so that the top ... Read More

Haskell Program To Find The Perfect Number

Akhil Sharma
Updated on 24-Apr-2023 11:37:54

501 Views

In haskell we can use list comprehension and brute-force method to find the perfect number. What is a Perfect Number? Perfect numbers are positive integers that are equal to the sum of their proper divisors. A divisor of a positive integer n is a positive integer that divides n exactly, leaving no remainder. A proper divisor is a divisor of n that is less than n itself. For example, the proper divisors of 6 are 1, 2, and 3, and the sum of these divisors is 1 + 2 + 3 = 6. Therefore, 6 is a perfect number.. Algorithm ... Read More

Haskell Program to Check Whether a Number is Prime or Not

Akhil Sharma
Updated on 24-Apr-2023 11:37:11

926 Views

To check whether a given number is prime or not we are going to use mod function and list comprehension method in Haskell. What is a Prime Number? A prime number is a positive integer greater than 1 that is only divisible by 1 and itself. In other words, a prime number cannot be written as the product of two smaller positive integers, except for 1 and itself. For example, the first few prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29. Algorithm Step 1 − The isPrime function is defined. Step 2 ... Read More

Haskell Program to Check if two strings are anagram

Akhil Sharma
Updated on 24-Apr-2023 11:36:12

554 Views

In Haskell we can check if given two strings are anagram or not using sort function and freqMap. What is Anagram? An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, the word "listen" is an anagram of the word "silent". Anagrams are often used in word play, puzzles, and other forms of entertainment. Algorithm Step 1 − The Data.List module is imported to use sort function. Step 2 − The isAnagram function using sort function is defined Step 3 ... Read More

Haskell Program to Check if a String is Numeric

Akhil Sharma
Updated on 14-Jul-2023 16:53:27

2K+ Views

In Haskell we can use read functions and Data.char library to find if a given string is numeric or not. The following example will give you a clear idea about the valid numeric values. For example, 121, 12321, and 1221 if entered as string are valid numeric values. Algorithm Step 1 − The isNumeric function using reads function is defined Step 2 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. In the main function, the string is passed to the isNumeric function. ... Read More

Haskell Program to Check Palindrome

Akhil Sharma
Updated on 24-Apr-2023 11:34:26

1K+ Views

This tutorial will help us in checking if any number is palindrome number or not using user-defined function and boolean functions in haskell. A palindrome number is a number that remains the same when its digits are reversed. The following example will give you a clear idea about Palindrome number. For example, 121, 12321, and 1221 are palindrome numbers, while 123, 1234, and 1212 are not. Algorithm Step 1 − The isPalindrome function using reverse function is defined as, isPalindrome str = str == reverse str. Step 2 − Program execution will be started from main function. The ... Read More

Advertisements