Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using map function
#1
I am getting following error:

Traceback (most recent call last):
File "./map_function.py", line 13, in <module>
name = map(name_split(person1,name),people)
TypeError: 'list' object is not callable

def name_split(person,name):

    name = person.split(' ')

    return (name)

global name

name = []

people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']

for person1 in people:

    name = map(name_split(name), people)

print name
Reply
#2
The first argument of map is the function which is called repeatedly with the elements of the iterable. Don't call the function when you pass it to a map function.

def name_split(name):
    return name.split()

people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']
splitted_names = list(map(name_split, people))
print(splitted_names)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020