Python Articles

Page 117 of 852

Find mismatch item on same index in two list in Python

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 3K+ Views

Sometimes we may need to compare elements in two python lists in terms of both their value and position or index. In this article we will see how to find out the elements in two lists at the same position which do not match in their value.Using for loopwe can design for loop to compare the values at similar indexes. Id the values do not match then we add the index to a result list. The for loop first fetches the value in the first index and then uses an if condition to compare it with values from the second ...

Read More

Find missing elements in List in Python

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 2K+ Views

If we have a list containing numbers, we can check if the numbers are contiguous or not and also find which numbers are missing from a range of numbers considering the highest number as the final value.With range and maxWe can design a for loop to check for absence of values in a range using the not in operator. Then capture all these values by adding them to a new list which becomes the result set.ExamplelistA = [1, 5, 6, 7, 11, 14] # Original list print("Given list : ", listA) # using range and max res = ...

Read More

Find missing numbers in a sorted list range in Python

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 1K+ Views

Given a list with sorted numbers, we want to find out which numbers are missing from the given range of numbers.With rangewe can design a for loop to check for the range of numbers and use an if condition with the not in operator to check for the missing elements.ExamplelistA = [1, 5, 6, 7, 11, 14] # Original list print("Given list : ", listA) # using range res = [x for x in range(listA[0], listA[-1]+1)                               if x not in listA] # Result ...

Read More

Python to Find number of lists in a tuple

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 395 Views

A python tuple is ordered and unchangeable. But it can also be made up of lists as its elements. Given a tuple made up of lists, let’s find out how many lists are present in the tuple.with len()In this approach we will apply the len function. The len() function will give the count of lists which are the elements of the tuple.ExampletupA = (['a', 'b', 'x'], [21, 19]) tupB = (['n', 'm'], ['z', 'y', 'x'], [3, 7, 89]) print("The number of lists in tupA :" , len(tupA)) print("The number of lists in tupB :" , len(tupB))OutputRunning the above code ...

Read More

Find the missing value from the given equation a + b = c in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 657 Views

Suppose we have one equation in this form: a + b = c, now any one of the terms of a, b or c is missing. We have to find the missing one.So, if the input is like ? + 4 = 9, then the output will be 5To solve this, we will follow these steps −delete all blank spaces from the string and change (+ and = to comma ', ')elements := a list of elements by splitting the string separated by commaidx := 0for i in range 0 to size of elements, doif elements[i] is not numeric, thenidx ...

Read More

Find the minimum time after which one can exchange notes in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 176 Views

Suppose there are n number of cashiers exchanging the money, at the moment, the i-th cashier had ki number of people in front of him/her. Now, the j-th person in the line to i-th cashier had m[i, j] notes. We have to find how early can one exchange his/her notes. We have to keep in mind that the cashier spent 5 seconds to scan a single note.After completing scanning of every note for the customer, he/she took 15 seconds to exchange the notes.So, if the input is like Input : n = 6, k = [12, 12, 12, 12, 12, ...

Read More

Find the number of consecutive zero at the end after multiplying n numbers in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 276 Views

Suppose we have an array with n numbers, we have to return the number of consecutive zero’s at the end after multiplying all the n numbers.So, if the input is like [200, 20, 5, 30, 40, 14], then the output will be 6 as 200 * 20 * 5 * 30 * 40 * 14 = 336000000, there are six 0s at the end.To solve this, we will follow these steps −Define a function count_fact_two() . This will take ncount := 0while n mod 2 is 0, docount := count + 1n := n / 2 (only the quotient as ...

Read More

Find the number of distinct pairs of vertices which have a distance of exactly k in a tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 314 Views

Suppose we have an integer k and also have a tree with n nodes, we have to count the number of distinct pairs of vertices which have a exact k distance.So, if the input is like k = 2then the output will be 4To solve this, we will follow these steps −N := 5005graph := adjacency list of size Nvertex_count := a 2d matrix of size 505 x 5005res := 0Define a function insert_edge() . This will take x, yinsert y at the end of graph[x]insert x at the end of graph[y]Define a function dfs() . This will take v, ...

Read More

Find the number of rectangles of size 2x1 which can be placed inside a rectangle of size n x m in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 241 Views

Suppose we have two values n and m; we have to find the number of rectangles of size 2x1 that can be set inside a rectangle of size n x m. There are few conditions, that we have to consider −Any two small rectangles cannot overlap.Every small rectangle lies completely inside the bigger one. It is permitted to touch the edges of the bigger rectangle.So, if the input is liken = 3, m = 3, then the output will be 4To solve this, we will follow these steps −if n mod 2 is same as 0, thenreturn(n / 2) * ...

Read More

Find the number of spectators standing in the stadium at time t in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 145 Views

There are n number of spectators in the stadium, and they are labeled from 1 to n. Now follow these cases −At time t1, the first spectator stands.At time t2, the second spectator stands.…At time tk, the k-th spectator stands.At time tk + 1, the (k + 1)-th spectator stands and the first spectator sits.At time tk + 2, the (k + 2)-th spectator stands and the second spectator sits.…At time tn, the n-th spectator stands and the (n – k)-th spectator sits.At time tn + 1, the (n + 1 – k)-th spectator sits.…At time tn + k, the ...

Read More
Showing 1161–1170 of 8,519 articles
« Prev 1 115 116 117 118 119 852 Next »
Advertisements