[Python] Need a code improvement in python for name abbreviation

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    def abbrev_name (name):
    output = ""
    arr = list(name.upper().split())
    for i in arr:
    output += i[0][0] + "."
    print(output)

    abbrev_name("albert einstein")


    I need the output of the Name separated by '.' Ex: Albert Einstein should give A.E,

    But i get A.E.

    Should i include a while statement to correct it. Help appreciated

    def ab(name):
    output = ""
    arr = list(name.upper().split())
    for i in arr:
    output += i[0][0] + "."
    print(output)


    ab("vineeth Jagati")

    Continue reading...

Compartilhe esta Página