Last active
December 13, 2023 11:23
-
-
Save immkavin-ranks/41ff6fa76b3a76f9dfb4c1b2964a85a7 to your computer and use it in GitHub Desktop.
Prints the alternate items/elements in a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sample list | |
a_list = [1, 65, 4, 2, 3, 9, 4, 8, 4, 20, 34, 6, 15, 17, 0, 23, 3] | |
print('Prints alternate items from first item:') | |
for item in a_list: | |
if a_list.index(item) % 2 == 0: # (a_list.index(item) + 1) % 2 != 0: | |
print(item) | |
print('Prints alternate items from second item:') | |
for item in a_list: | |
if (a_list.index(item) + 1) % 2 == 0: | |
print(item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment