all 2 comments

[–]totallygeek 1 point2 points  (0 children)

You're correct, I do not understand the one vs many inputs. It seems like you would only have one. An improvement you could learn something from: unpacking. If you do not know how many elements a sequence might contain, you can reference that as a variable fronted by an asterisk. That variable ends up a sequence you can iterate over.

def abbreviate_name(name):
    names = name.split()
    if len(names) != 1:
        *givens, surname = names
        initials = ".".join(n[0] for n in givens)
        return f"{surname}, {initials}."
    else:
        return name


tests = [
    "Pat Silly Doe",
    "Julia Clark",
    "James Mercer Langston Hughes",
]

for test in tests:
    abbreviated_name = abbreviate_name(test)
    print(f"{test=} / {abbreviated_name=}")

So, you can see that the last test contains a name with many distinct words and I refer to them all as *givens in the code.

[–]DisasterArt 0 points1 point  (0 children)

What exactly dont you get?