Python Forum
have homework to add a list to a list using append.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
have homework to add a list to a list using append.
#1
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.
Reply
#2
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])
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Quote:
encryptedPassword = passwordEncrypt(unencryptedPassword, encryptionKey)
passwords.append(website, passwordEncrypt)

Two things:
  1. You assign a value to variable encryptedPassword but you are using a variable named passwordEncrypt.
  2. You want to append a new list to the list "passwords", but you are adding the contents of two variables.
So use:
passwords.append([website, encryptedPassword])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with list homework eyal123 5 1,611 Nov-18-2022, 03:46 PM
Last Post: deanhystad
  how to reverse a list and store in another list in python SuperNinja3I3 6 3,231 Aug-14-2022, 06:36 PM
Last Post: DeaD_EyE
Question Python - List - Int List sophi 8 2,464 Apr-21-2022, 07:55 PM
Last Post: sophi
  Homework - List containing tuples containing dicti Men 4 1,980 Dec-28-2021, 12:37 AM
Last Post: Men
  Sorting list - Homework assigment ranbarr 1 2,202 May-16-2021, 04:45 PM
Last Post: Yoriz
  look at first letter in list and append word for assertion mapypy 3 1,898 Feb-06-2021, 05:45 PM
Last Post: buran
  Check if a list exists in given list of lists Daniel94 2 2,208 Apr-07-2020, 04:54 PM
Last Post: deanhystad
  list of strings to list of float undoredo 3 2,631 Feb-19-2020, 08:51 AM
Last Post: undoredo
  arrays sum list unsupported operand type(s) for +=: 'int' and 'list' DariusCG 7 4,075 Oct-20-2019, 06:24 PM
Last Post: Larz60+
  Search character from 2d list to 2d list AHK2019 3 2,439 Sep-25-2019, 08:14 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020