Sunday, July 7, 2019

IslandT: Create integer list from a number with python

Given a number, return a list of integer with python function.

In this chapter, we are given a number and we need to return a list of integer based on that number, for example, number 3 will return a list of [1,2,3].

We will first create an empty array, then we will loop through that number and push the new number (count + 1) into that empty list.

def monkey_count(n):
    li = []
    for i in range(n):
        li.append(i+1)
    return li

There is one easy solution as compared to the above, let me know in the comment box below this post.



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...