1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Python - AttributeError: 'str' object has no attribute 'append'

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I keep receiving this error when I try to run this code for the line "encoded.append("i")":

    AttributeError: 'str' object has no attribute 'append'

    I cannot work out why the list won't append with the string. I'm sure the problem is very simple Thank you for your help.

    def encode(code, msg):
    '''Encrypts a message, msg, using the substitutions defined in the
    dictionary, code'''
    msg = list(msg)
    encoded = []
    for i in msg:
    if i in code.keys():
    i = code
    encoded.append(i)
    else:
    encoded.append(i)
    encoded = ''.join(encoded)
    return encoded

    Continue reading...

Compartilhe esta Página