Been working through the jeopardy challenge project (https://www.codecademy.com/practice/projects/this-is-jeopardy).
Looking through the solution, the challenge suggests using one of the built in python functions (all()), however this is the first time ive seen this and can’t get my head around how it works in the example.
So from what I gather, all() is the equivalent of this:
def all(iterable): for element in iterable: if not element: return False return True
In the code example it is utilised in this way:
# Filtering a dataset by a list of words def filter_data(data, words): # Lowercases all words in the list of words as well as the questions. Returns true is all of the words in the list appear in the question. filter = lambda x: all(word.lower() in x.lower() for word in words) # Applies the labmda function to the Question column and returns the rows where the function returned True return data.loc[data["Question"].apply(filter)]
Im very confused about how this function is accepting a for loop as an argument as well as what the temp variable “word” actually relates to.
Has anyone come across this, or can anyone share a half decent explanation of this function and its usage. Just from the example, it seems very useful but is a couple of levels above my current python understanding.