- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find only even indexed elements from list in Python
Suppose we have a list of elements called nums. We have to filter out all odd indexed elements, so only return even indexed elements from that list.
So, if the input is like nums = [5,7,6,4,6,9,3,6,2], then the output will be [7, 4, 9, 6]
To solve this, we will follow these steps −
- use python list slicing strategy to solve this problem
- start from index 1, end at the end of list and increase each step by 2, so the slicing
- syntax is [1::2]
Example
Let us see the following implementation to get better understanding −
def solve(nums): return nums[1::2] nums = [5,7,6,4,6,9,3,6,2] print(solve(nums))
Input
[5,7,6,4,6,9,3,6,2]
Output
[7, 4, 9, 6]
- Related Articles
- Program to find number of elements can be removed to make odd and even indexed elements sum equal in Python
- Program to find sum of odd elements from list in Python
- Python program to find N largest elements from a list
- JavaScript Sum odd indexed and even indexed elements separately and return their absolute difference
- Program to find duplicate item from a list of elements in Python
- Python program to find sum of elements in list
- Python Program to Reverse only First N Elements of a Linked List
- Program to find the kth missing number from a list of elements in Python
- Absolute Difference of even and odd indexed elements in an Array (C++)?
- Python program to remove Duplicates elements from a List?
- Python Program to Remove Palindromic Elements from a List
- Python Program to Put Even and Odd elements in a List into Two Different Lists
- Absolute Difference of even and odd indexed elements in an Array in C++?
- Python program to print even numbers in a list
- Python – Find the distance between first and last even elements in a List

Advertisements