Python Program to Print List Items at Odd Position

Write a Python program to print list items at the odd position or odd index position. In this example, we use the list slicing starts at 0, incremented by 2, and ends at list length (end of the list).

odList = [2, 4, 7, 11, 14, 22, 19, 90]

print('Printing the List Items at Odd Position')
print(odList[0:len(odList):2])
Python Program to Print List Items at Odd Position

In this program, we used the for loop range to iterate list items and print list items at the odd index position.

odList = [36, 48, 77, 55, 90, 128, 193, 240]

for i in range(0, len(odList), 2):
    print(odList[i], end = '  ')
36  77  90  193 

Python program to print list items at odd position using a while loop

odList = [14, 35, 78, 90, 120, 67, 98]

i = 0
while i < len(odList):
    print(odList[i], end = '  ')
    i = i + 2
14  78  120  98  

In this list items at odd position example, the for loop iterates from 0 to list length. The if condition checks whether the index position divides by two equals 0. If true, print the number.

import numpy as np

odlist = []
odListTot = int(input("Total List Items to enter = "))

for i in range(1, odListTot + 1):
    odListvalue = int(input("Please enter the %d List Item = "  %i))
    odlist.append(odListvalue)


print('\nPrinting the List Items at Odd Position')
for i in range(0, len(odlist), 2):
    print(odlist[i], end = '  ')

print('\nPrinting the List Items at Odd Position')
for i in range(len(odlist)):
    if i % 2 == 0:
        print(odlist[i], end = '  ')
Total List Items to enter = 8
Please enter the 1 List Item = 14
Please enter the 2 List Item = 24
Please enter the 3 List Item = 34
Please enter the 4 List Item = 44
Please enter the 5 List Item = 54
Please enter the 6 List Item = 64
Please enter the 7 List Item = 74
Please enter the 8 List Item = 84

Printing the List Items at Odd Position
14  34  54  74  
Printing the List Items at Odd Position
14  34  54  74