The following example shows the error I am getting when trying to use a string function inside a function call to map. I need help with why this happening. Thanks.
>>> s=["this is a string","python python python","split split split"]
>>> map(split,s)
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
map(split,s)
NameError: name 'split' is not defined
though split() is an in-built function, but it still throws this error?
It will work fine if you use
str.split()I.e,
gives:
The error message states:
NameError: name 'split' is not defined, so the interpreter doesn’t recognizesplitbecausesplitis not a built-in function. In order for this to work you have to associatesplitwith the built-instrobject.Update: Wording improved based on @Ivc’s helpful comments/suggestions.