Monday, October 21, 2019

IslandT: Python array list’s count method

In this example, we will use the count method from the Python array list to decide which phrase to return from a function that will accept an array list consists of good and bad ideas.

In the below example, you need to decide which phrase to return from the array list which consists of good ideas ‘good’ and bad ideas ‘bad’. If there are one or two good ideas, return ‘Publish!’, if there are more than 2 return ‘I smell a series!’. If there are no good ideas, as is often the case, return ‘Fail!’.

def well(x):

    if x.count('good') > 2:

        return 'I smell a series!'
        
    elif x.count('good') > 0:

        return 'Publish!'

    else:

        return 'Fail!'

Write down your own python answer in below comment box.

If you like this post do share the post on any social media site to help this site to grow, thank you.



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