- 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
Python - Assign a specific value to Non Max-Min elements in Tuple
When it is required to assign a specific value to the non max-min elements in a tuple, the ‘max’ method, the ‘min’ method, the ‘tuple’ method and a loop can be used.
The ‘max’ method returns the maximum value among all of the elements in an iterable. The ‘min’ method returns the minimum value among all of the elements in an iterable.
The ‘tuple’ method converts a given value/iterable into a tuple type.
Below is a demonstration for the same −
my_tuple = (25, 56, 78, 91, 23, 11, 0, 99, 32, 10) print("The tuple is : ") print(my_tuple) K = 5 print("K has been assigned to " + str(K)) my_result =  for elem in my_tuple: if elem not in [max(my_tuple), min(my_tuple)]: my_result.append(K) else: my_result.append(elem) my_result = tuple(my_result) print("The tuple after conversion is : " ) print(my_result)
The tuple is : (25, 56, 78, 91, 23, 11, 0, 99, 32, 10) K has been assigned to 5 The tuple after conversion is : (5, 5, 5, 5, 5, 5, 0, 99, 5, 5)
- A tuple is defined, and is displayed on the console.
- The value of ‘K’ is defined and displayed.
- An empty list is created.
- The tuple is iterated over, and the maximum and minimum values are determined.
- If these values are not in the tuple, it is appended to the empty list.
- This list is converted to a tuple.
- It is then displayed as output on the console.
- Sorting max to min value in MySQL
- max() and min() in Python
- Min-Max Heaps
- How to define a MIN and MAX value for EditText in Android?
- Use of min() and max() in Python
- Program to fill Min-max game tree in Python
- Symmetric Min-Max Heaps
- Find Min-Max in heterogeneous list in Python
- Minimum value of “max + min” in a subarray in C++
- How to define a MIN and MAX value for EditText in Android using Kotlin?
- Create a vertical slider with custom min, max, and initial value in Java
- Assign range of elements to List in Python
- How to SELECT min and max value from the part of a table in MySQL?
- How to create a horizontal slider with custom min, max, and initial value in Java
- Python – Test if elements of list are in Min/Max range from other list