Search code examples
pythonmap-function

Python: Call function that returns two strings inside map function


Hello I am trying to create a function that is called inside a map function, splits the string that have been passed as input and returns two processed strings. To be more understood here is my code (it doesn't seem to return anything).

def prepare_data(data):
    x1, x2 = data.split(" ", 1) # split only 1 time at the space
    return x1.strip("\""), x2 



if __name__ == "__main__":
  print(list(map(prepare_data, '"word_1" rest of sentence')))

Any suggestions would be appreciated. Cheers!


Solution

  • You need to make an iterable List from your sentence. Use:

    x = map(prepare_data, ['"word_1" rest of sentence'])
    
    print(list(x))