Found 33676 Articles for Programming

How to Multiply All Items in a Tuple in Python

Rohan Singh
Updated on 18-Jul-2023 16:12:35

4K+ Views

In Python, tuples are immutable sequences that can contain a collection of elements. We can multiply all the items in a tuple using various methods like using a for loop, using the reduce() function from the functools module, using list comprehension, and the math.prod() function, etc. In this article, we will explore all these methods and implement the functions to multiply all items in a tuple in Python. Method 1:Using for loop This method is straightforward and easy to understand. It involves iterating over each item in the tuple and multiplying them one by one using a for loop. Syntax ... Read More

How to Group Strings on Kth character using Python?

Rohan Singh
Updated on 18-Jul-2023 16:08:15

372 Views

In Python, we can group strings on the kth character using several methods like using a dictionary, leveraging the groupby() function from itertools, and utilizing the defaultdict from the collection module. Grouping strings on the kth character is useful when manipulating and performing complex operations on strings. In this article, we will explore different methods to group tuples by their kth index element, using various techniques, and demonstrate their implementation. Method 1:Using a Dictionary One approach to group strings on the Kth character is by using a dictionary. We can iterate through the list of strings, extract the Kth character ... Read More

Scheduling without Deadline

Pranavnath
Updated on 18-Jul-2023 16:49:42

396 Views

In the field of computer science, scheduling tasks and processes proficiently is a significant perspective of optimizing resource utilization and moving forward by and large framework execution. Traditional scheduling problems regularly include relegating tasks with particular deadlines to resources, pointing to meet those deadlines whereas minimizing costs or maximizing throughput. Be that as it may, in certain scenarios, scheduling without deadlines gets to be a significant and curious issue to address. This article investigates the concept of scheduling without deadlines and its noteworthiness in computer science. Understanding Scheduling without Deadlines Scheduling without deadlines refers to the allocation of tasks ... Read More

How to Get the Nth Word in a Given String using Python?

Rohan Singh
Updated on 18-Jul-2023 16:04:43

1K+ Views

We can get the Nth Word in a Given String in Python using string splitting, regular expressions, split() method, etc. Manipulating strings is a common task in programming, and extracting specific words from a string can be particularly useful in various scenarios. In this article, we will explore different methods to extract the Nth word from a given string using Python. Method 1:Splitting the String This method involves splitting the string into a list of words and accessing the desired word based on its index. Syntax words = string.split() Here, the split() method splits the string based on whitespace ... Read More

Selfish Round Robin CPU Scheduling

Pranavnath
Updated on 18-Jul-2023 16:27:40

726 Views

Scheduling algorithms in the operating system execute the processes based on their arrival time or by their priority. Each algorithm chooses the processes that are in waiting to ready queue by preemption or non-preemption methods. Preemptive algorithms provide access to the CPU to the process which has higher priority and preempt any other process which is already running with lower priority. But in the case of non-preemptive scheduling, when processes start their execution, it cannot be preemptive even when higher priority processes are in the ready state. The traditional round-robin scheduling algorithm is a preemptive one where each process gets ... Read More

Sum of numbers formed by consecutive digits present in a given string

Shubham Vora
Updated on 18-Jul-2023 17:31:33

493 Views

Problem Statement We have given a string str containing the numeric and alphabetical characters. We need to find the sum of all numbers represented by a continuous sequence of digits available in the given string. Sample Examples Input str = “12were43” Output 55 Explanation The sum of 12 and 43 is equal to 55. Input str = “1a2c3d” Output 6 Explanation The sum of 1, 2, and 3 is 6. Input str = “werderfrewsf” Output 0 Explanation It gives 0 in the output as the string contains no digit. Our logic to solve the ... Read More

Modify a Sentence By Reversing Order Of Occurrences Of All Palindrome Words

Shubham Vora
Updated on 18-Jul-2023 17:27:29

183 Views

Problem Statement We have given a string str containing a total of N words. We need to find all palindrome words in the given string and create a new string by reversing the order of all palindrome words. Sample Examples Input str = ‘nayan was gone to navjivan eye hospital’ Output ‘eye was gone to navjivan nayan hospital’ Explanation The string contains three palindrome words: nayan, navjivan, and eye. We have reversed the order of all three words and kept all other words the same. Input ‘Hello, users! How are you?’ Output ‘Hello, users! How are you?’ ... Read More

Minimum Removals Required To Place All 0s Before 1s In a Binary String

Shubham Vora
Updated on 18-Jul-2023 17:25:35

371 Views

Problem Statement We have given binary string str, and we require to remove minimum characters from the string such that we can place all zeros before 1. Sample Examples Input str = ‘00110100111’ Output 3 Explanation Here, we can achieve output 3 in two ways. We can either remove arr[2], arr[3], and arr[5] or arr[4], arr[6], and arr[7] from the string. Input str = ‘001101011’ Output 2 Explanation We can remove arr[4] and arr[6] to place all zeros before 1. Input str = ‘000111’ Output 0 Explanation In the given str, all ... Read More

Python - Leaf and Non-Leaf Nodes Dictionary

Asif Rahaman
Updated on 18-Jul-2023 14:43:05

431 Views

Dictionary is an important data structure in Python which consists of key value pairs. They were originally designed to be non−iterable objects. However recently Python extended its support for iteration of the dictionary objects too. A nested dictionary has nodes, leaf, non−nodes etc. In this article we will understand how to manipulate leaf and non−leaf nodes using dictionaries in Python. What are leaf and non leaf nodes? Before we deep dive into the codes we first need to understand what are the leaf and non leaf nodes in dictionary data types. Leaf node:Those nodes which do not ... Read More

Minimum Number That Can Be Obtained By Applying '+' And '*' Operations On Array Elements

Shubham Vora
Updated on 18-Jul-2023 17:16:15

139 Views

Problem Statement We have given an array of length ‘N’ containing some positive integers. Also, we have given the string of length ‘N-1’ containing only ‘*’ and ‘+’ characters, where ‘*’ is a multiplication operator, and ‘+’ is an addition operator. We require to perform the arithmetic operation with array elements in such a way that we can get a minimum positive integer value. Sample Examples Input array = [1, 2, 3], str = “*+” Output 5 Explanation It is the resultant value of ((1*2) + 3). Input array = [3, 3, 3, 3], str = ‘*++’ ... Read More

Advertisements