- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Tuple Division in Python
When it is required to perform tuple division in Python, the 'zip' method and generator expressions can be used.
The zip method takes iterables, aggregates them into a tuple, and returns it as the result.
Generator is a simple way of creating iterators. It automatically implements a class with '__iter__()' and '__next__()' methods and keeps track of the internal states, as well as raises 'StopIteration' exception when no values are present that could be returned.
Below is a demonstration of the same −
my_tuple_1 = ( 7, 8, 3, 4, 3, 2) my_tuple_2 = (9, 6, 8, 2, 1, 4) print ("The first tuple is : " ) print(my_tuple_1) print ("The second tuple is : " ) print(my_tuple_2) my_result = tuple(elem_1 // elem_2 for elem_1, elem_2 in zip(my_tuple_1, my_tuple_2)) print("The divided tuple value is : " ) print(my_result)
The first tuple is : (7, 8, 3, 4, 3, 2) The second tuple is : (9, 6, 8, 2, 1, 4) The divided tuple value is : (0, 1, 0, 2, 3, 0)
- Two tuples are defined, and displayed on the console.
- The lists are iterated over, and they are zipped using the 'zip' method.
- The first element is taken and 'divided' with the second element from both the tuples using the '//' operator.
- This is then converted to a tuple.
- This operation is assigned to a variable.
- This variable is the output that is displayed on the console.
- Division Operators in Python?
- Python – Consecutive Division in List
- Flatten tuple of List to tuple in Python
- Tuple multiplication in Python
- Division Operator in C#
- Division Operators in Java
- Optimal Division in C++
- Unpacking a Tuple in Python
- Tuple Data Type in Python
- Delete Tuple Elements in Python
- Tuple XOR operation in Python
- DFA based division
- Frequency Division Multiplexing
- Time Division Multiplexing
- Code Division Multiplexing