0
Please.. I am having issues parsing this code. I don't seem to understand how the output gives []. Can anyone explain to me?
3 ответов
+ 2
In general: this snippet filters out those values('$dollar', '@at','%modulu' ) that do not contain '#x27; and '%' symbols.
lambda operator creates an unnamed function that runs function 'any' through the values list. 'any' itself returns those elements that contains '#x27; and '%' symbols. But 'not any' does a inverse selection. That is why you get those values that DO NOT contain '#x27; and '%' symbols:
f = lambda x: not any(p in x for p in fil)
here: 'p in fil' runs across the list of #x27; and '%' symbols one by one. So 'p' first takes '#x27; and then in 'p in x' checks whether 'x' contains this synbol. Then the same goes with '%' synbol. 'x' in its turn is a variable that takes a value from the list ['$dollar', '@at','%modulu'].
+ 1
strawdog thanks for pointing that out.. I just corrected it.. I still need explanation for the code though
0
Looks like you've missed a comma in your list:
lst = ['$dollar', '@at', '%modulu']
^this one