Wednesday, March 13, 2019

codingdirectional: Keep on removing the second item in a list with python

In this chapter we will look at another question from CodeWars, this question goes like this: Given a list of items, create a method which will keep on removing the next item in the list and returning a list without the next item.

The keyword here is to remove every next item in a list.

def remove_every_other(my_list):
    keep = []
    for i in range(len(my_list)):
        if(i % 2 == 0):
            keep.append(my_list[i])
    return keep

A very simple solution for a simple 8 Kyu question on CodeWars.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...