• + 1 comment

    Why install new packages when you can go with standard Python libraries? Wouldn't this be a better, more portable Python 3? This involves no additional package installs like others are using in their discussion solutions with scipy, numpy, pandas, etc.

    # With standard lib imports only
    from statistics import mean, median
    
    def basicstats(numbers):
        print(round(mean(numbers),1))
        print(median(numbers))
        print(max(sorted(numbers), key=numbers.count))
    
    input() # Don't need array length, so replace var
    numbers = list(map(float, input().split()))
    basicstats(numbers)
    

    EDIT: Removed import of collections, as mode can be done without.

    Of course, if scipy is already included in an application, this isn't an issue.

    Though, introducing additional non-standard packages adds complexity to the supply-chain (includes adding security complexity). For example, this year there was an Arbitrary Code Execution vulnerability associated with numpy that could be remedied only with an update to the package version.

    Installing and depending on third-party packages in Python just because they assist in completing this particular task, when the standard libraries are capable with just as little code, is a problem. Imagine if you were needing to do this same task in an existing application, and a developer said they wanted to introduce scipy (which includes numpy as a dependency) packages in order to get the mode, median, and mean of certain data? Adding two new third-party packages? It's overkill and could be revealing a lack of experience/understanding of standard libraries.

    Installing scipy and numpy adds ~45mb worth of files ( > 3k files) into the project to complete this task, which sounds like overkill.