Python: Remove and print every third number from a list of numbers until the list becomes empty
Python Basic - 1: Exercise-3 with Solution
Write a Python program that removes and prints every third number from a list of numbers until the list is empty.
Python Code :
def remove_nums(int_list): #list starts with 0 index position = 3 - 1 idx = 0 len_list = (len(int_list)) while len_list>0: idx = (position+idx)%len_list print(int_list.pop(idx)) len_list -= 1 nums = [10,20,30,40,50,60,70,80,90] remove_nums(nums)
30 60 90 40 80 50 20 70 10
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to create all possible strings by using 'a', 'e', 'i', 'o', 'u'. Use the characters exactly once.
Next: Write a Python program to find unique triplets whose three elements gives the sum of zero from an array of n integers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join