
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 10476 Articles for Python

566 Views
When it is required to split the tuple into 'n' groups, the list comprehension can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are important contains since they ensure read-only access.The list comprehension is a shorthand to iterate through the list and perform operations on it.Below is a demonstration for the same −ExampleLive Demomy_tuple = (12, 34, 32, 41, 56, 78, 9, 0, 87, 53, 12, 45, 12, 6) print ("The tuple ... Read More

232 Views
When it is required to modify the list of tuple, the 'zip' method and the list comprehension can be used.The zip method takes iterables, aggregates them into a tuple, and returns it as the result.The list comprehension is a shorthand to iterate through the list and perform operations on it.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on). A list of tuple basically contains tuples enclosed in a list.Below is a demonstration for the same −ExampleLive Demomy_list_1 = [('Hi', 1), ('there', 2), ('Jane', 3)] my_list_2 = ... Read More

630 Views
When it is required to remove tuples that have a duplicate first value from a given set of list of tuples, a simple 'for' loop, and the 'add' and 'append' methods can be used.Below is a demonstration for the same −ExampleLive Demomy_input = [(45.324, 'Hi Jane, how are you'), (34252.85832, 'Hope you are good'), (45.324, 'You are the best.')] visited_data = set() my_output_list = [] for a, b in my_input: if not a in visited_data: visited_data.add(a) my_output_list.append((a, b)) print("The list of tuple is : ") print(my_input) print("The list of tuple after ... Read More

381 Views
When it is required to unpack a tuple of list, the 'reduce' method can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are important contains since they ensure read-only access.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A tuple of list contains multiple lists, which are enclosed in '(' and ')'.The 'reduce' method is used to apply a specific ... Read More

4K+ Views
The binary search algorithm is the fastest algorithm to search for an element in a sorted array. It works by dividing the array into two halves and checking if the target element is in the left or right half, thus reducing the search space by half with each iteration. Binary Search Using Recursion The following are the steps to implement binary search using recursion: Define a binSearch() function that accepts the array, the left index, the right index, and the target that you want to search. Check if the ... Read More

5K+ Views
To implement binary search without recursion, the program takes a sorted list and a key as input. It uses the Binary search method, which is an efficient way to find a specific item in a sorted list. It works by repeatedly dividing the list in half. This method works by first comparing the key with the middle element of the list. If the key matches the middle element, the search is successful, and the index is returned. If the key is less than the middle element, the search continues on the left subarray; if it's greater, the search shifts to ... Read More

295 Views
When it is required to remove the matching tuples from two list of tuples, the list comprehension can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list.The list comprehension is a shorthand to iterate through the list and perform operations on it.Below is a demonstration for the same −ExampleLive Demomy_list_1 = [('Hi', 'there'), ('Jane', 'Hi'), ('how', 'are'), ('you', '!')] my_list_2 = [('Hi', 'there'), ('Hi', 'Jane')] print("The first list is : ") print(my_list_1) print("The second ... Read More

199 Views
When it is required to sort the tuple based on the occurrence of the first element, the dict.fromkeys method can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list.The 'dict.fromkeys' method will return a dictionary with a specific key and a value.Below is a demonstration for the same −ExampleLive Demodef sort_on_occurence(my_lst): my_dict = {} for i, j in my_lst: my_dict.setdefault(i, []).append(j) return([(i, *dict.fromkeys(j), len(j)) for i, ... Read More

688 Views
When it is required to remove the strings froma tuple, the list comprehension and the 'type' method can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list.The list comprehension is a shorthand to iterate through the list and perform operations on it.The 'type' method returns the class of the iterable passed to it as an argument.Below is a demonstration for the same −ExampleLive Demomy_list = [('Hi', 45, 67), ('There', 45, 32), ('Jane', 59, 13)] ... Read More

239 Views
When it is required to get the summation of a list of tuple, the list comprehension and the 'sum' method can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list.The list comprehension is a shorthand to iterate through the list and perform operations on it.The 'sum' method is used to add the elements of an iterable, where the iterable is passed as an argument to the method.Below is a demonstration for the same −ExampleLive Demomy_list ... Read More