Printing specific elements from a list

The following program will print the 1st, 3rd and 5th elements of the list only.


list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for index, item in enumerate(list):
    if index==0 or index==2 or index==4:
        print(index, item)








Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes