Beginning Question about Python functions, parameters...

Terry Reedy tjreedy at udel.edu
Tue Nov 24 23:29:35 CET 2009


Peter Otten wrote:
> Terry Reedy wrote:

>> remember exactly what was stored. Maybe a typo.
> 
> That's a bug in the store() function
> 
> # as posted
> def store(data, full_name):
>     names = full_name.split()
>     if len(names) == 2: names.insert(1, '')
>     labels = 'first', 'middle', 'last'
>     for label, name in zip(labels, names):
>         people = lookup(data, label, name)
>     if people:
>         people.append(full_name)
>     else:
>         data[label][name] = [full_name]
> 
> # what was probably intended
> def store(data, full_name):
>     names = full_name.split()
>     if len(names) == 2: names.insert(1, '')
>     labels = 'first', 'middle', 'last'
>     for label, name in zip(labels, names):
>         people = lookup(data, label, name)
>         if people:
>             people.append(full_name)
>         else:
>             data[label][name] = [full_name]

(Note indent error, which I overlooked)
It is a nuisance when people post untested code, without identifying it 
as such. Publishing untested but trivial-to-test code like this (one 
print statement needed), especially in a book for learners, is really bad.

(I am trying to do better in the book I am working on.)

tjr




More information about the Python-list mailing list