We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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 onlyfromstatisticsimportmean,mediandefbasicstats(numbers):print(round(mean(numbers),1))print(median(numbers))print(max(sorted(numbers),key=numbers.count))input()# Don't need array length, so replace varnumbers=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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 0: Mean, Median, and Mode
You are viewing a single comment's thread. Return to all comments →
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.
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 includesnumpy
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
andnumpy
adds ~45mb worth of files ( > 3k files) into the project to complete this task, which sounds like overkill.