Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 have homework to add a list to a list using append.
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.
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 -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

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])

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Check if a list exists in given list of lists Daniel94 2 171 Apr-07-2020, 04:54 PM
Last Post: deanhystad
  list of strings to list of float undoredo 3 233 Feb-19-2020, 08:51 AM
Last Post: undoredo
  arrays sum list unsupported operand type(s) for +=: 'int' and 'list' DariusCG 7 503 Oct-20-2019, 06:24 PM
Last Post: Larz60+
  Search character from 2d list to 2d list AHK2019 3 286 Sep-25-2019, 08:14 PM
Last Post: ichabod801
  I donr know how to search from 2d list to 2d list AHK2019 1 257 Sep-25-2019, 01:59 AM
Last Post: ichabod801
  sort a list alphabeticaly without changing the original list Holmen 5 824 Jan-27-2019, 01:49 PM
Last Post: Holmen
  Dictionary/List Homework ImLearningPython 22 2,719 Dec-17-2018, 12:12 AM
Last Post: ImLearningPython
  making a dictionary from a list, one key with multiple values in a list within a list rhai 4 1,030 Oct-24-2018, 06:40 PM
Last Post: LeSchakal
  List of far points of two list antoniomancera 2 1,306 Nov-16-2017, 08:45 AM
Last Post: antoniomancera
  list of list to list of tuple? student8 2 1,225 Nov-14-2017, 08:06 AM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)