w3resource

Python: Select the odd items of a list

Python List: Exercise - 46 with Solution

Write a Python program to select the odd items of a list.

Pictorial Presentation of Odd Numbers:

Odd Numbers

Sample Solution:-

Python Code:

x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(x[::2])

Sample Output:

[1, 3, 5, 7, 9] 

Flowchart:

Flowchart: Select the odd items of a list

Odd Numbers between 1 to 100:

Odd Numbers between 1 to 100

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to convert a pair of values into a sorted unique array.
Next: Write a Python program to insert an element before each element of a list.

What is the difficulty level of this exercise?



Inviting useful, relevant, well-written and unique guest posts