Mar-19-2018, 03:29 PM
The following code is a solution for a string-related problem:
I'm not familiar with third brackets in for loop, nor how class methods are being called here and how "c" is being passed as a parameter to "method".
The same code can be written in the following way:
NB: The problem corresponding to the codes is from HackerRank
for method in [str.isalnum, str.isalpha, str.isdigit, str.islower, str.isupper]: print any(method(c) for c in s)Here, "s" is a string.
I'm not familiar with third brackets in for loop, nor how class methods are being called here and how "c" is being passed as a parameter to "method".
The same code can be written in the following way:
t = type(s) for method in [t.isalnum, t.isalpha, t.isdigit, t.islower, t.isupper]: print any(method(c) for c in s)Can anyone kindly tell me what's happening in these codes?
NB: The problem corresponding to the codes is from HackerRank