Friday, June 28, 2019

IslandT: Count the pair of duplicate number with Python

In this example, we will create a function in Python which will return the total number of duplicate pair of numbers within a list. For example, if we enter [0,0,0,0] into that function it will return 2 because there are two pairs of duplicate number within that list.

def duplicates(arr):
    
    global count
    count = 0
    while(len(arr) > 0):
        find = arr.pop(0) 
        for i in range(len(arr)) :
            if find == arr[i] :
                count += 1
                del arr[i]
                break
    return count

There is another solution written in Kotlin, if you are interested to know more then read this post.

In the next article, we will start another new Python project which will stay for at least a month, if you want to contribute to that project you can do so by creating a pool request on Github, stay tune and get ready for the new Python project starting from the next article onward!



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