- 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 – Extract Kth element of every Nth tuple in List
When it is required to extract ‘K’th element of every ‘N’th tuple in a list, a simple iteration and the ‘append’ method is used.
Below is a demonstration of the same −
my_list = [(54, 51, 23), (73, 24, 47), (24, 33, 72), (64, 27, 18), (63, 24, 67), (12, 25, 77), (31, 39, 80),(33, 55, 78)] print("The list is :") print(my_list) K = 1 print("The value of K is :") print(K) N = 3 print("The value of N is :") print(N) my_result =  for index in range(0, len(my_list), N): my_result.append(my_list[index][K]) print("The result is :") print(my_result)
The list is : [(54, 51, 23), (73, 24, 47), (24, 33, 72), (64, 27, 18), (63, 24, 67), (12, 25, 77), (31, 39, 80), (33, 55, 78)] The value of K is : 1 The value of N is : 3 The result is : [51, 27, 39]
A list of tuple is defined and is displayed on the console.
The values for K and N are defined and are displayed on the console.
An empty list is defined.
The list is iterated over, and the element at a specific index at ‘K’ is appended to the empty list
This is the output that is displayed on the console.
- Kth Column Product in Tuple List in Python
- Python – Append List every Nth index
- Extract digits from Tuple list Python
- Get maximum of Nth column from tuple list in Python
- Closest Pair to Kth index element in Tuple using Python
- Kth smallest element after every insertion in C++
- Consecutive Nth column Difference in Tuple List using Python
- Filter Tuples by Kth element from List in Python
- Maximum element in tuple list in Python
- Accessing nth element from Python tuples in list
- Python – Cross Join every Kth segment
- Update each element in tuple list in Python
- Python program to covert tuple into list by adding the given string after every element
- Python program to convert tuple into list by adding the given string after every element