
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

659 Views
A list can contain other list as its elements. In this article we are equal to find the sublist with maximum value which are present in a given list.With max and lambdaThe max and the Lambda function can together be used to give that sublist which has the maximum value.Example Live DemolistA = [['Mon', 90], ['Tue', 32], ['Wed', 120]] # Using lambda res = max(listA, key=lambda x: x[1]) # printing output print("Given List:", listA) print("List with maximum value: ", res)OutputRunning the above code gives us the following result −Given List: [['Mon', 90], ['Tue', 32], ['Wed', 120]] List with maximum value: ['Wed', ... Read More

260 Views
Suppose we have a list of words, a list of single letters and score for every character. We have to find the maximum score of any valid set of words formed by using the given letters.We may not use all characters in letters and each letter can only be used once. Score of letters 'a', 'b', 'c', ... ,'z' is given by score[0], score[1], ... , score[25] respectively.So, if the input is like words = ["god", "good", "toc", "cat"], letters = [a, g, o, o, d, d, d, c, t, t] and score = [5, 0, 8, 3, 0, 0, ... Read More

333 Views
In this article we are required to find that number from the list which occurs odd number of times in the given list. We are also required to use the Lambda function and the reduce function.We design a function where the reduce function is used by applying the Lambda function to check if the element is present odd number of times.Example Live Demofrom functools import reduce def oddcount(i): print(reduce(lambda x, y: x ^ y, i)) listA = [12, 34, 12, 12, 34] print("Given list:", listA) print("The element present odd number of times:") oddcount(listA)OutputRunning the above code gives us the following ... Read More

2K+ Views
Suppose we have an array called nums of positive integers. We have to select some subset of nums, then multiply each element by an integer and add all these numbers. The array will be a good array if we can get a sum of 1 from the array by any possible subset and multiplicand.We have to check whether the array is good or not.So, if the input is like [12, 23, 7, 5], then the output will be True, this is because If we take numbers 5, 7, then 5*3 + 7*(-2) = 1To solve this, we will follow these ... Read More

3K+ Views
In this article we will find all those elements from a list which start with specific letter.With index and lowerWe use the lower function so that the test later can match with the first letter of the the elements in the list irrespective of the case. Then we use the index at 0 so that the first letter of the elements in a list are compared with the test letter.Example Live DemolistA = ['Mon', 'Tue', 'Wed', 'Thu'] # Test with letter test = 'T' # printing original list print("Given list " ,listA) # using lower and idx res = [idx for ... Read More

8K+ Views
In this article we will see how to find the element which is most common in a given list. In other words, the element with highest frequency.With max and countWe apply why the set function to get the unique elements of the list and then keep account of each of those elements in the list. Finally apply a max function to get the element with highest frequency.Example Live Demo# Given list listA = [45, 20, 11, 50, 17, 45, 50, 13, 45] print("Given List:", listA) res = max(set(listA), key = listA.count) print("Element with highest frequency:", res)OutputRunning the above code gives us ... Read More

677 Views
A 2D list has list as its element. In other words it is a list of lists. In this article we are required to find the element which is most common among all the lists inside a list.With max and countWe design a follow with a in condition to check for the presence of an element in a given sublist. Then we apply the max function along with the count function to get the the element with maximum frequency.Example Live Demodef highest_freq(lst): SimpleList = [el for sublist in lst for el in sublist] return max( SimpleList, key= SimpleList.count) # ... Read More

314 Views
Suppose we have a rectangle of size n x m. We have to find the minimum number of integers sided square objects that can tile the rectangles.So, if the input is like n = 2 and m = 3,then the output will be 3, as we need three blocks.To solve this, we will follow these steps −Define one map mres := infDefine a function dfs(), this will take n, m, an array h, cnt,if cnt >= res, then −returnisFull := truepos := -1, minH := inffor initialize i := 1, when i

387 Views
We are given a list of lists. In the inner lists or sublists we are required to find the maximum value in each.With max and inWe design a for loop with in condition and apply the max function to get the maximum value in each of the sublist.Example Live DemoAlist = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # Given list print("The given list: ", Alist) # Use Max res = [max(elem) for elem in Alist] # Printing max print("Maximum values from each element in the list: ", res)OutputRunning the above code gives us the following result −The given ... Read More

1K+ Views
Suppose we have n different tasks, where every task is scheduled to be done from startTime[i] to endTime[i], for that task we algo get profit of profit[i]. We know the startTime , endTime and profit lists, we have to find the maximum profit we can take such that there are no 2 tasks in the subset with overlapping time range. If we choose a task that ends at time X we will be able to start another task that starts at time X.So, if the input is like startTime = [1, 2, 3, 3], endTime = [3, 4, 5, 6] ... Read More