- 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 program to construct Equidigit tuples
When it is required to construct equi-digit tuples, the ‘//’ operator and the list slicing is used.
Below is a demonstration of the same
my_list = [5613, 1223, 966143, 890, 65, 10221] print("The list is :") print(my_list) my_result =  for sub in my_list: mid_index = len(str(sub)) // 2 element_1 = str(sub)[:mid_index] element_2 = str(sub)[mid_index:] my_result.append((int(element_1), int(element_2))) print("The resultant list is :") print(my_result)
The list is : [5613, 1223, 966143, 890, 65, 10221] The resultant list is : [(56, 13), (12, 23), (966, 143), (8, 90), (6, 5), (10, 221)]
A list is defined and is displayed on the console.
An empty list is defined.
The list is iterated over and the middle index is obtained.
The list slicing is used to obtained values before middle index and after middle index.
These elements are assigned to two variables.
These are appended to the empty list by converting them to integers.
This is displayed as output on the console.
- Python Pandas - Construct an IntervalArray from an array-like of tuples
- Python program to find Tuples with positive elements in List of tuples
- Python program to Order Tuples using external List
- Python program to find Tuples with positive elements in a List of tuples
- How to split Python tuples into sub-tuples?
- How to Concatenate tuples to nested tuples in Python
- Python program to Sort Tuples by their Maximum element
- Python program to sort a list of tuples alphabetically
- Python program to convert a list of tuples into Dictionary
- Program to construct the lexicographically largest valid sequence in Python
- Combining tuples in list of tuples in Python
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python program to sort tuples in increasing order by any key.
- Python program to sort a list of tuples by second Item
- Python program to sort tuples by frequency of their absolute difference