Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Could you explain the inner function inside count_words function? #17

Answered by jsalbr
ahmad-alismail asked this question in Q&A
Discussion options

You must be logged in to vote

Sure. inner_update is called in this line:

    df_name[column_name].map(inner_update) # call inner function

So the parameter doc to inner_update is the value of df_name[column_name]. To make it more clear, the code line above is equivalent to

    df_name[column_name].map(lambda doc: inner_update(doc)) # call inner function

So it's basically the value of your "Text" column in the example.

And as nested functions in Python have access to all parameters of the surrounding function, we can simply use preprocess within the inner functions without explicit handover as a parameter.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ahmad-alismail
Comment options

@jsalbr
Comment options

jsalbr Jul 26, 2022
Collaborator

Answer selected by jsalbr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants