Complexity and performance
There are many ways to write this type of function and the best is determined by the number of input states. In your example you have 6 different input states 1-5 and NaN.
The least number of steps to parse the string is 1 and the worst requires 6 steps. The average time, assuming equal distribution of input, is (1 + 2 + ...
Super short review;
The code should handle the presence or the absence ? in a transparent way
The code should probably check for /supplier/ instead of ?
That leaves me with
const resource = '/supplier/';
I liked the fact that you used the sum() builtin function, but I have no idea what sOM or sOMCache mean in sOM = sum([int(x) for x in sOMCache]) — "Sum of marks", maybe? But the capitalization is weird by Python standards, and this isn't a cache — you wouldn't just eject data from this "cache", would you?
I think, as you probably ...
there was a question that required to get the inputs from STDIN and use collections.namedtuple()
Really? I don't think that HackerRank would enforce using a named tuple, and using a named tuple isn't hugely helpful here. Plus, if you were to use a named tuple, I would sooner expect that it capture the four fields in every line rather than one point at the ...
While it may be unlikely to occur, the URL could contain a hostname with a top-level domain supplier. Currently .supplies is registered to Donuts Inc and someday URLs could have a TLD with supplier, which would lead the current code to not correctly find the target text.
const supplyUrl = "https://my.supplier/supplier/tariffSelectionG_E5449168?t=...
I think for any url related task you have two good tools as
The URL API
The URLPattern API
With the URL constructor you may do like;
var url = new URL("https://any-api/supplier/tariffSelectionG_E5449168?t=randomChars"),
tariffCode = url.pathname.slice(url.pathname.lastIndexOf("/")+1);
URLPattern API, on the other hand is ...
You could use a map or object, but it would be just another way of doing it and I wouldn't call it better tbh.
One thing you can change is the default block. All the other cases return a number while default returns a string. Depending on the use case, you can either return a value like -1, NaN, undefined, or even throw an exception throw 'Not a valid value!'...
I guess that without more context of how the function is used, it's hard to say what the default return should be.
Your read_file returns headers and sequences implicitly correlated by their order. A model that is easier to work with is to make sequence class instances that each have their own header and sequence string.
If you accept fasta_file, then why do you hard-code yeast.fna?
yeast.fna's original name is GCF_000146045.2_R64_genomic.fna. It seems unwise to discard ...
It's possible that I misunderstand the purpose of the exercise but since you are processing a list of students, I would expect that the namedtuple would represent a student object with properties like name, class, marks etc. You are still dealing with list indexes, and your present implementation of namedtuple does not really ...
If you can, use the URL constructor. It is a bit clearer semantically:
const supplyUrl = new URL("https://any-api/supplier/tariffSelectionG_E5449168?t=randomChars");
const parts = supplyUrl.pathname.split("/");
// the 0th item is empty since the pathname starts with a slash
const tariff = parts;
For the purposes of international collaboration, for better or worse the de-facto language of software development is English, so:
versanddaten -> ShippingData
vorlage -> Template
DateiEndung -> FileExtension
It is a great idea to localise user-facing content to German, but code should be in English.
"Informations" should be "...
How to improve your code:
Rather than using the XML document and XML elements, use a concrete class for books and their collection.
With the help of the book class you can now to de-serialize the response of API.
In addition to that, add GetBookName() and other relevant behavior to the book's class
I believe your response XML will look as follows: