have homework to add a list to a list using append. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: have homework to add a list to a list using append. (/thread-21724.html) |
have homework to add a list to a list using append. - celtickodiak - Oct-11-2019 So I am attempting to add a list to a list with append, but I don't think it is working, as I cannot call the list back out using another option. This is the list here: passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]This is the code to attempt to add the two inputs as a list: if(choice == '3'): print("What website is this password for?") website = input() print("What is the password?") unencryptedPassword = input()There are other choices, but they aren't important at the moment. Finally my code attempting to add the inputs to the list, as a list using append, I should also mention that I have to encrypt the password using a Caesar Cypher, but I can figure that out later: encryptedPassword = passwordEncrypt(unencryptedPassword, encryptionKey) passwords.append(website, passwordEncrypt)I am unsure what I am doing wrong, and where to go from here. RE: have homework to add a list to a list using append. - ichabod801 - Oct-11-2019 I do this all the time, but usually with tuples. You can only append one item, but you want to append two. But note that passwords is a list of lists, each sub-list having two items. So you append one list with two items: passwords.append([website, passwordEncrypt]) RE: have homework to add a list to a list using append. - ibreeden - Oct-11-2019 Quote:encryptedPassword = passwordEncrypt(unencryptedPassword, encryptionKey) passwords.append(website, passwordEncrypt) Two things:
passwords.append([website, encryptedPassword]) |